-
Notifications
You must be signed in to change notification settings - Fork 12
tools: accept "help" top-level command, show usage on errors #174
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
Conversation
help
top-level commandhelp
top-level command
I don't necessarily want to throw the h short option away for --help. I think it's far less consistently available than --help, and sometimes it makes sense to use it to align with use of -h for "human readable" or "host name" or whatever else. I agree that a top-level help command is valuable, though! |
help
top-level command
I have pushed some changes to the branch:
|
ah! good changes. you prompted me to check in a few places about println!("{}", opts.usage(&out));
};
- let res = opts.parse(std::env::args_os().skip(1))?;
+ let res = match opts.parse(std::env::args_os().skip(1)) {
+ Ok(res) => res,
+ Err(e) => {
+ eprintln!("Error: {}", e);
+ usage();
+
+ // If we bail!() out here, we'll get another `Error: ...` printed to stderr
+ // by Rust. We've done all the reporting we want though, so just exit(1)
+ // now.
+ std::process::exit(1);
+ }
+ };
+
if res.opt_present("help") {
usage();
return Ok(()); that should guide users a bit better than the status quo of
while not necessarily eating |
I think that's reasonable, but I would print the usage first and then just bail in the usual way with the error. Sometimes the usage information can be more than a an entire screen vertically, and it's super irritating to be hit in the face with it unexpectedly and then to have to go and hunt for what you did wrong! If we put the error last, at least it's right there where your eyes are with the next shell prompt.
I've pushed a change to make it look like the above, and to ensure that the usage text ends up on stderr in a failure case, or stdout (for grep, etc) if you explicitly requested it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, thanks! works for me. i was only leaning towards "error first, then usage" because that's what other tools i was comparing against also do. error at the end seems pretty reasonable.
i'd approve, as this is now ~100% @jclulow code, but github doesn't let me self-approve. does need an approver before squash and merge, so feel free to do the honours 🫡
helios-build
has supported--help
since forever, but as @rmustacc found in #12 and i rediscovered yesterday, not-h
nor a top-level "help" command. seems like it'd be good to accept all of--help
,-h
,helios-build help
, or the bare./helios-build
to get usage information, so this change does that.also, because it's in
baseopts
, this means-h
is now a flag for all the subcommands too.