alecthomas / kingpin

CONTRIBUTIONS ONLY: A Go (golang) command line and flag parser
MIT License
3.5k stars 273 forks source link

Show boolean value type default in flag formatting. #317

Closed geekodour closed 4 years ago

geekodour commented 4 years ago

Fixes: #243

Unsure if contradicts with kingpins design to have the implicit --no-name flags.

cc: @autarch @alecthomas

Signed-off-by: Hrishikesh Barman hrishikeshbman@gmail.com

autarch commented 4 years ago

Thanks for working on this, @geekodour.

My thinking is that this isn't the right way to do this. Showing output like "--foo=false" seems quite confusing. If someone actually passes that they'll get an error:

package main

import (
    "fmt"

    "github.com/alecthomas/kingpin"
)

var boolFlag = kingpin.Flag("foo", "Foo").Default("true").Bool()

func main() {
    kingpin.Parse()
    fmt.Printf("%v\n", *boolFlag)
}
$> go run ./foo/main.go --foo=false
main: error: unexpected false, try --help
exit status 1

I think the original suggestion of showing --foo or --no-foo depending on the flag's default value was the right approach. It'd also be nice to change the help output to clarify this, so we'd get something like this:

--no-foo    Disable the foo feature. The default is to enable this feature.
--bar       Enable the bar feature. The default is to disable this feature.

The exact wording of that needs some work, since enable/disable may not work for every flag.

alecthomas commented 4 years ago

Yes, thanks for the PR, but I agree with @autarch. Whatever the help displays should be usable by the user.