-
Notifications
You must be signed in to change notification settings - Fork 147
Print the help when --help or -h is unexpectedly encountered. #264
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
Print the help when --help or -h is unexpectedly encountered. #264
Conversation
1bbe801
to
c58b619
Compare
While using the new functionality I discovered two deficiencies my initial implementation, hence the force pushes. It's now greedily searching over the remaining arguments for
Because the parse error happens on the first unmatched argument. With the latest version, we get (for the last command):
Which unfortunately doesn't print anything on how to run it on a file, I think that's a bug, but unrelated to this PR, I'm going to try to flash the file instead of pursuing this unrelated bug and try to get the wifi firmware into a partition :) |
I've no opinion on whether we should include this change or not (that's @will-v-pi 's decision to make), but I wonder if you ought to remove the |
You can't run |
Also, please target all PRs at the |
c58b619
to
7e9e0c3
Compare
As always; maintainer's choice, I ran into something that I thought was worth fixing for myself :)
Yeah, maybe we should. Initially I didn't in case someone typo'd a
Ah, perfect, thanks that's indeed what I needed.
I've changed the target branch. It would be good to include this in the pull request template, that way anyone filing a PR will read this requirement. |
7e9e0c3
to
8a243f4
Compare
I've now also rebased my branch on the |
When dcbeb00 eventually gets merged to the |
I was having a go at testing this PR, and it doesn't work for these commands (and possibly others):
|
It works exactly as intended though? In these examples you provide the Against the master branch (de8ae5a);
I did not state this PR would introduce blanket support for |
Alternatively, a simple implementation to fix this by handling all With that commit:
The approach here breaks if anyone ever introduces the |
Thanks, I think this option is better - if you could push this commit, I'm happy to merge it I think matching both |
This inserts the 'help' command at the start of the argument list in case the '-h' or '--help' argument is encountered anywhere on the commandline.
8a243f4
to
045e13f
Compare
Sounds good, maybe my original approach was unnecessarily conservative.
I've rebased the commit on the latest upstream master and pushed it to this branch. |
Most binaries used on Linux support the '--help' argument, this is a convention specified by the GNU project, as well as in the clig.
Currently, adding
--help
after a failing command gives an error, following by an note at the end on how to get the help. Actually getting the help usually involves pressing the up arrow, removing the erroneous--help
at the end, moving the cursor to afterpicotool
to inserthelp
and then succesfully printing out the help.This commit adds a new error type to the parser to distinguish between parse errors, and errors that can be identified as an attempt to obtain the help. This help error is raised only if an unexpected argument called
--help
is encountered, or an unexpected option-h
.In the
main.cpp
this specific error is now caught and handled on appropriately, still relying on the outer catch problematic parse errors, like using command names that don't exist.Above the line is the commit message, I considered an example too long to be included in it, but before this commit the behaviour is as follows:
With this commit, it instead does:
Behaviour when subcommands don't exist is unmodified:
Neither is behaviour when a secondary subcommand is not specified, so in case of
picotool partition --help
, the behaviour is unmodified as that situation already prints the available subcommands. It's really only handling--help
and-h
at the end of the commandline, which is muscle memory for many people that live in their terminals.I at first tried to modify the signature of
match
to use an outparam, but that didn't work as any throws would still end up being handled by the outer throw. I didn't want to return a boolean return to indicate the help is desired, so instead I decided to subclass from theparse_error
and make a more specific flavour of that.I've only tested this on Debian GNU/Linux 12, I hope it works with MSVC, I did not find a CONTRIBUTING.md file or
.clang-format
file, so not sure if there's any tests I should/can run.