1
0
mirror of https://github.com/packwiz/packwiz.git synced 2025-04-28 17:16:30 +02:00

Remove viper settings for acceptable-versions --add/--remove flags

This commit is contained in:
comp500 2023-10-22 11:32:38 +01:00
parent bee8e601d4
commit 1f09959be6

@ -5,7 +5,6 @@ import (
"github.com/packwiz/packwiz/cmdshared" "github.com/packwiz/packwiz/cmdshared"
"github.com/packwiz/packwiz/core" "github.com/packwiz/packwiz/core"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/unascribed/FlexVer/go/flexver" "github.com/unascribed/FlexVer/go/flexver"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"os" "os"
@ -42,8 +41,7 @@ var acceptableVersionsCommand = &cobra.Command{
} }
} }
// Check our flags to see if we're adding or removing // Check our flags to see if we're adding or removing
if viper.GetBool("settings.acceptable-versions.add") { if flagAdd {
// Adding
acceptableVersion := args[0] acceptableVersion := args[0]
// Check if the version is already in the list // Check if the version is already in the list
if slices.Contains(currentVersions, acceptableVersion) { if slices.Contains(currentVersions, acceptableVersion) {
@ -64,8 +62,7 @@ var acceptableVersionsCommand = &cobra.Command{
// Print success message // Print success message
prettyList := strings.Join(currentVersions, ", ") prettyList := strings.Join(currentVersions, ", ")
fmt.Printf("Added %s to acceptable versions list, now %s\n", acceptableVersion, prettyList) fmt.Printf("Added %s to acceptable versions list, now %s\n", acceptableVersion, prettyList)
} else if viper.GetBool("settings.acceptable-versions.remove") { } else if flagRemove {
// Removing
acceptableVersion := args[0] acceptableVersion := args[0]
// Check if the version is in the list // Check if the version is in the list
if !slices.Contains(currentVersions, acceptableVersion) { if !slices.Contains(currentVersions, acceptableVersion) {
@ -136,12 +133,13 @@ var acceptableVersionsCommand = &cobra.Command{
}, },
} }
var flagAdd bool
var flagRemove bool
func init() { func init() {
settingsCmd.AddCommand(acceptableVersionsCommand) settingsCmd.AddCommand(acceptableVersionsCommand)
// Add and remove flags for adding or removing specific versions // Add and remove flags for adding or removing specific versions
acceptableVersionsCommand.Flags().BoolP("add", "a", false, "Add a version to the list") acceptableVersionsCommand.Flags().BoolVarP(&flagAdd, "add", "a", false, "Add a version to the list")
acceptableVersionsCommand.Flags().BoolP("remove", "r", false, "Remove a version from the list") acceptableVersionsCommand.Flags().BoolVarP(&flagRemove, "remove", "r", false, "Remove a version from the list")
_ = viper.BindPFlag("settings.acceptable-versions.add", acceptableVersionsCommand.Flags().Lookup("add"))
_ = viper.BindPFlag("settings.acceptable-versions.remove", acceptableVersionsCommand.Flags().Lookup("remove"))
} }