Bad boolean Flag value is interpreted as Argument
dbenque opened this issue · comments
David Benque commented
Using boolean Flag, and trying to assign a value to it is not reported as an error, instead the value is interpreted as an Argument of the program:
func main() {
var (
app = kingpin.New(filepath.Base(os.Args[0]), "My App.").DefaultEnvars()
testBool = app.Flag("test-bool", "test-bool").Bool()
//args = app.Arg("my args", "arg list").Required().Strings()
)
kingpin.MustParse(app.Parse(os.Args[1:]))
fmt.Printf("test-bool=%s\n",strconv.FormatBool(*testBool))
//fmt.Printf("args=%s\n",*args)
}
This would report an error if you run it (expected):
go run main.go --test-bool=false
--> main: error: unexpected false, try --help
Now if you remove the comments to run the program with Arguments, here is what you get:
go run main.go --test-bool=false myArg
test-bool=true
args=[false myArg]
Not only the list of arguments contains the string value false
but the boolean is set to true
.
Alec Thomas commented
Kingpin doesn't support this approach, you can use --no-test-bool
to negate a flag.