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

flag: print default value when false for boolean flags #63150

Closed
Rajan-226 opened this issue Sep 21, 2023 · 4 comments
Closed

flag: print default value when false for boolean flags #63150

Rajan-226 opened this issue Sep 21, 2023 · 4 comments

Comments

@Rajan-226
Copy link

What version of Go are you using (go version)?

$ go version go1.21.0 darwin/arm64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

I defined a boolean flag with default value as false.

flag.Bool("boolVar", false, "Trying bool variable")

I'm running go run main.go -h

What did you expect to see?

I expect to get default value of boolVar like I get when it's true.
image

What did you see instead?

I'm not getting default value when it's false.
image

@Rajan-226
Copy link
Author

I would like to pick dev for this if you consider it as a good first issue.

@seankhliao seankhliao changed the title affected/package: flag, Default value not getting printed if false flag: print default value when false for boolean flags Sep 21, 2023
@seankhliao
Copy link
Member

sure, send a CL / PR

@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 21, 2023
@ianlancetaylor
Copy link
Contributor

Please always post ordinary text output as plain text, not as an image. Plain text is much easier to read. Thanks.

@ianlancetaylor
Copy link
Contributor

This is intentional behavior. The flag package only displays the default flag when that value is not the zero value of the type. The code is at https://go.googlesource.com/go/+/refs/heads/master/src/flag/flag.go#628. Thanks for reporting this but we don't plan to change it.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2023
@mvdan mvdan removed the NeedsFix The path to resolution is known, but the work has not been done. label Sep 22, 2023
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

4 participants