-
Notifications
You must be signed in to change notification settings - Fork 310
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
When flags.HelpFlag used, -h shows up as positional arg #107
Comments
This is a side effect from help being treated as an error. Basically what happens currently when an error happens is that you get as the returned args all the remaining arguments from and including the error location. This is more or less intentional, but I can see how that doesn't work out for the help flag hijacking the error system to return early. We could special case help to act as double dash, i.e. pass-through of all remaining args, and then return that (along with the error). Ideally we would have a better solution for doing the help handling, maybe we can add a HelpHandler field in the parser which people can set to handle what should happen after the help has been shown (which usually would be an os.Exit(1)). |
How about
This would remove -h/--help from the remaining arguments, would remove some extra help handling which is currently scattered and put help handling into one parser method. |
I went with the easy way out, which is to just not prepend the -h arg to the retargs when the error is I'd still like to see a better way to implement |
When I create a parser using
flags.NewParser
and specify theflags.Default
option so the help message option is added, I am seeing an unexpected result when setting the-h/--help
option on execution.When I run a program with the
-h
option, the help message is printed as expected but-h
gets passed through as a leftover argument. Same goes for--help
. When I set other options (ones I've defined), those options don't get passed through as leftover arguments.Is this expected? Here is a gist that shows how I am producing the issue: https://gist.github.com/ctryan3/8dd552b02fdd8ae8efa1
The text was updated successfully, but these errors were encountered: