replace isFlagSet with Changed
This commit is contained in:
parent
e0a3ce95f2
commit
a306b7790c
14
cmd/root.go
14
cmd/root.go
@ -54,16 +54,6 @@ func addServerFlags(flags *pflag.FlagSet) {
|
|||||||
flags.StringP("baseurl", "b", "", "base url")
|
flags.StringP("baseurl", "b", "", "base url")
|
||||||
}
|
}
|
||||||
|
|
||||||
func isFlagSet(flags *pflag.FlagSet, key string) bool {
|
|
||||||
set:= false
|
|
||||||
flags.Visit(func(flag *pflag.Flag) {
|
|
||||||
if flag.Name == key {
|
|
||||||
set = true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return set
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: we could simply bind the flags to viper and use IsSet.
|
// NOTE: we could simply bind the flags to viper and use IsSet.
|
||||||
// Although there is a bug on Viper that always returns true on IsSet
|
// Although there is a bug on Viper that always returns true on IsSet
|
||||||
// if a flag is binded. Our alternative way is to manually check
|
// if a flag is binded. Our alternative way is to manually check
|
||||||
@ -73,7 +63,7 @@ func getStringViperFlag(flags *pflag.FlagSet, key string) (string, bool) {
|
|||||||
value, _ := flags.GetString(key)
|
value, _ := flags.GetString(key)
|
||||||
|
|
||||||
// If set on Flags, use it.
|
// If set on Flags, use it.
|
||||||
if isFlagSet(flags, key) {
|
if flags.Changed(key) {
|
||||||
return value, true
|
return value, true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +234,7 @@ func quickSetup(flags *pflag.FlagSet, d pythonData) {
|
|||||||
noauth, err := flags.GetBool("noauth")
|
noauth, err := flags.GetBool("noauth")
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
if !isFlagSet(flags, "noauth") && v.IsSet("noauth") {
|
if !flags.Changed("noauth") && v.IsSet("noauth") {
|
||||||
noauth = v.GetBool("noauth")
|
noauth = v.GetBool("noauth")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user