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