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

View File

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