From 9597007953548847544be4cddc366c2bf26000a3 Mon Sep 17 00:00:00 2001 From: Patryk Hegenberg Date: Fri, 20 Jun 2025 13:24:09 +0200 Subject: [PATCH] refactor: replace for loop over slice --- cmd/package_commands.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/package_commands.go b/cmd/package_commands.go index 09c60cb..7c8b44c 100644 --- a/cmd/package_commands.go +++ b/cmd/package_commands.go @@ -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)