Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The default value for boolean is not showing in the cli #444

Closed
MohamadTahir opened this issue Aug 11, 2024 · 1 comment
Closed

The default value for boolean is not showing in the cli #444

MohamadTahir opened this issue Aug 11, 2024 · 1 comment

Comments

@MohamadTahir
Copy link

Hello, the default value for boolean flags is not show in the cli when doing --help, for exmaple I have the following struct

type CLI struct {
	Test bool `default:true`
}

main function


func Run() {
	cli := &CLI{}

	ctx := kong.Parse(
		cli,
		kong.Description("A Test CLI Tool."),
		kong.Vars{
			"version": "0.0.1",
		},
	)
	ctx.Run()
}

when checking the help output in the cli

go run main.go --help

Usage: main [flags]

A Test CLI Tool.

Flags:
  -h, --help    Show context-sensitive help.
      --test
@alecthomas
Copy link
Owner

That's kind of deliberate, as when boolean flags are used without explicitly setting a value (eg. --test) they will always set the value to true. That is, they should almost always be false by default, and having the default value in the help is largely redundant.

If you want the value to be set to either true or false I would recommend using negatable:"" and adding something to the description defining the default state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants