-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: UnquoteUsage checks for IsBoolFlag() method presence but doesn't actually call it #53473
Comments
…ded tests for PrintDefaults output checking for 3 cases
Fix is easy, I think. Can you please provide a complete runnable example that shows the problem? |
* exit with status 1 if grpcping -health isn't SERVING. fixes #588 * add a _down grpc server that will be always NOT_SERVING * add a test for _down * add also status e2e test and preop for 1.33.0 * fix the status test * Use generics to tremendously shrink/improve the dflag/ code (left the tests unchanged or added to them to test indeed the implementation is compatible; they could be cleaned as well * Add test for Parse error case. Added test in logger to cover the setting normalization * update the sample and move the common stuff into the new generic file, add one more test * use type aliases for backward compatibility * added slice and set to generics version * linter * last one: dynjson; also improve testify compatibility by showing actual line numbers * had to remove IsBoolFlag from generic because of golang/go#53473 - added tests for PrintDefaults output checking for 3 cases * linter
Thanks @robpike, here you go (simplified without all the generics etc): package main
import "flag"
type NotBool struct{}
func (f *NotBool) IsBoolFlag() bool {
return false
}
func (f *NotBool) Set(v string) error {
return nil
}
func (f *NotBool) String() string {
return ""
}
func main() {
value := NotBool{}
flag.Var(&value, "test", "test usage, line above should be -test value")
flag.PrintDefaults()
} output
expected:
also on https://go.dev/play/p/URV2A7fhI4- and https://github.com/ldemailly/go-flag-bug/blob/main/bool_flag_issue.go |
Change https://go.dev/cl/431102 mentions this issue: |
* exit with status 1 if grpcping -health isn't SERVING. fixes #588 * add a _down grpc server that will be always NOT_SERVING * add a test for _down * add also status e2e test and preop for 1.33.0 * fix the status test * Use generics to tremendously shrink/improve the dflag/ code (left the tests unchanged or added to them to test indeed the implementation is compatible; they could be cleaned as well * Add test for Parse error case. Added test in logger to cover the setting normalization * update the sample and move the common stuff into the new generic file, add one more test * use type aliases for backward compatibility * added slice and set to generics version * linter * last one: dynjson; also improve testify compatibility by showing actual line numbers * had to remove IsBoolFlag from generic because of golang/go#53473 - added tests for PrintDefaults output checking for 3 cases * linter
* exit with status 1 if grpcping -health isn't SERVING. fixes #588 * add a _down grpc server that will be always NOT_SERVING * add a test for _down * add also status e2e test and preop for 1.33.0 * fix the status test * Use generics to tremendously shrink/improve the dflag/ code (left the tests unchanged or added to them to test indeed the implementation is compatible; they could be cleaned as well * Add test for Parse error case. Added test in logger to cover the setting normalization * update the sample and move the common stuff into the new generic file, add one more test * use type aliases for backward compatibility * added slice and set to generics version * linter * last one: dynjson; also improve testify compatibility by showing actual line numbers * had to remove IsBoolFlag from generic because of golang/go#53473 - added tests for PrintDefaults output checking for 3 cases * linter
any chance to backport to 1.19? |
This doesn't seem to me to fit the backport requirements (https://github.com/golang/go/wiki/MinorReleases). |
yes I guess it's not a big bug (even though the fix is really small and safe) - oh well... will wait then, thanks |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?not relevant (but apple silicon M1 macos)
What did you do?
Implemented a generic set of flag extension and part of the generic includes:
Yet despite returning false for the non bool, flag.PrintDefaults through UnquoteUsage thinks all my types are booleans (don't require a
value
) and thus my usage output regressed from for instanceWhat did you expect to see?
value
still outputWhat did you see instead?
nothing
ps: I can workaround by making the bool type special but it's unfortunate
The text was updated successfully, but these errors were encountered: