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
dev-cmd/extract: Improve the usage instructions #10400
dev-cmd/extract: Improve the usage instructions #10400
Conversation
Review period will end on 2021-01-26 at 00:00:00 UTC. |
8c8b13a
to
fb65137
Compare
- A friend got an error message when trying to use `brew extract` and it wasn't immediately obvious to me why. The usage banner only mentioned the "formula" argument, which they'd provided. This improves the error message when there aren't enough arguments so that others have a chance of figuring out how to use this command without having to look at the code for `extract_args`. Before: ``` ➜ brew extract --version='1.4' libftdi Usage: brew extract [--version=] [--force] formula ... [...] Error: Invalid usage: this command requires a formula argument ``` After: ``` ➜ brew extract --version='1.4' libftdi Usage: brew extract [options] formula tap [...] Error: Invalid usage: This command requires at least 2 named arguments. ``` - I don't like the "at least 2" phrasing here but that's a dive into the arg parsing code that I don't have time for right now. An alternative was `named_args [:formula, :destination_tap]`, but that gave the error message "requires formula or destination_tap" which wasn't great either. I also tried `min: 2, max: 2` and that was the same "at least 2" message.
8f76600
to
49b9b6c
Compare
Okay, I modified the Now, I also added a new Here is the updated message for $ brew extract --version='1.4' libftdi
Usage: brew extract [--version=] [--force] formula tap
[...]
Error: Invalid usage: This command requires exactly 2 formula or tap arguments. I think this is a good middle ground. If the error message could still use improvement, I'd say the best way to do it is to manually catch the begin
args = extract_args.parse
rescue Homebrew::CLI::NumberOfNamedArgumentsError
raise UsageError, "new message"
end |
And commit `brew man` changes
Those changes to the wording and the tests look good to me. Thanks, @Rylan12! |
Thanks, @issyl0! ✅ from me on the changes here (I won't officially approve for now to avoid approving my own changes 😅) |
NamedArgumentCountError? Either way, 👍 on the pull request. |
My only hesitation with this name is that the error is only thrown when there is an exact number of named args. A different exception is thrown when the number of arguments is above the minimum and below the maximum. To be fair, though, this is still better than what I had before (which has the same problem). In total, there are three error types:
Maybe it makes the most sense to just have one error class called something like Thoughts? I'm also not sure whether |
Review period skipped due to |
Thanks all! |
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?brew man
locally and committed any changes?brew extract
and it wasn't immediately obvious to me why. The usage banner only mentioned the "formula" argument, which they'd provided. This improves the error message when there aren't enough arguments so that others have a chance of figuring out how to use this command without having to look at the code forextract_args
.Before:
After:
named_args [:formula, :destination_tap]
, but that gave the error message "requires formula or destination_tap" which wasn't great either. I also triedmin: 2, max: 2
and that was the same "at least 2" message.I still cannot run
brew man
locally because something in my gems is messed up andronn
doesn't exist, so I'm going to try to re-learn enough manpage syntax to edit them by hand.