refactor: replace for loop over slice

This commit is contained in:
Patryk Hegenberg 2025-06-20 13:24:09 +02:00
parent 73881bf9b5
commit 9597007953

View file

@ -4,6 +4,7 @@ import (
"codeberg.org/Pata1704/system_setup_tool/internal/utils"
"fmt"
"os"
"slices"
"sort"
"github.com/spf13/cobra"
@ -42,11 +43,9 @@ var addCmd = &cobra.Command{
} else {
packages := viper.GetStringSlice(fmt.Sprintf("package_managers.%s.packages", manager))
for _, pkg := range packages {
if pkg == name {
fmt.Printf("Package %s is already present in the configuration for %s\n", name, manager)
return
}
if slices.Contains(packages, name) {
fmt.Printf("Package %s is already present in the configuration for %s\n", name, manager)
return
}
packages = append(packages, name)