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: In parseOne (), why (false, ErrHelp) is returned when only "- help" or "- h" is passed as an argument? #30655

Closed
zabio3 opened this issue Mar 7, 2019 · 1 comment

Comments

@zabio3
Copy link

zabio3 commented Mar 7, 2019

A custom flag.FlagSet returns a distinguished error, ErrHelp, when it sees the -help flag.

Where the code is written


if name == "help" || name == "h" { // special case for nice help message.
	f.usage()
	return false, ErrHelp
}

But, If the program is called with the wrong argument, I think that you should return explanation of usage and error.

Therefore, if you pass arguments that only "help" or "h", I think that f.usage () will be executed and (true, nil) will be returned.

I would like to know why it is implemented like this.

@zabio3 zabio3 changed the title In parseOne (), why (false, ErrHelp) is returned when only "- help" or "- h" is passed as an argument? flag: In parseOne (), why (false, ErrHelp) is returned when only "- help" or "- h" is passed as an argument? Mar 7, 2019
@mvdan
Copy link
Member

mvdan commented Mar 7, 2019

See https://golang.org/pkg/flag/#ErrorHandling; it's possible to configure a flagset to return errors. "The user requested the help text" is a kind of error, because the tool shouldn't continue as normal.

In the future, for questions, see https://github.com/golang/go/wiki/Questions.

@mvdan mvdan closed this as completed Mar 7, 2019
@golang golang locked and limited conversation to collaborators Mar 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants