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: package level nor CommandLine var docs mention default behavior of -h or -help flags #66708

Closed
aaraney opened this issue Apr 7, 2024 · 2 comments

Comments

@aaraney
Copy link

aaraney commented Apr 7, 2024

Out of the box, the default flag.FlagSet variable, flag.CommandLine, will print usage information and exit 0 if -h or -help is given and a flag with that name was not already registered. This nicety feature is great, however I discovered by surprise! Looking through the flag documentation at 1.22.2, I found mention of the -h and -help flags in ErrHelp's documentation, but nothing at the package level or on CommandLine specifically about this default behavior.

ErrHelp is the error returned if the -help or -h flag is invoked but no such flag is defined.

I am happy to open a PR to improve documentation in this area if it would be well receive :).

@seankhliao
Copy link
Member

it's part of FlagSet.Parse https://pkg.go.dev/flag#FlagSet.Parse

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 7, 2024
@aaraney
Copy link
Author

aaraney commented Apr 7, 2024

The return value will be ErrHelp if -help or -h were set but not defined.

@seankhliao, the above snippet from the documentation describe entirely different behavior. CommandLine.Parse doesn't return anything and will exit 0 if -h or -help is provided. This is undocumented.

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

No branches or pull requests

3 participants