refactor: replace for loop over slice
This commit is contained in:
parent
73881bf9b5
commit
9597007953
1 changed files with 4 additions and 5 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue