dev-cmd/extract: Improve the usage instructions

- 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.
This commit is contained in:
Issy Long 2021-01-23 16:59:33 +00:00
parent bf448def73
commit 49b9b6cf3f
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
4 changed files with 4 additions and 4 deletions

View File

@ -83,6 +83,7 @@ module Homebrew
sig { returns(CLI::Parser) }
def extract_args
Homebrew::CLI::Parser.new do
usage_banner "`extract` [<--version>`=`] [<--force>] <formula> <tap>"
description <<~EOS
Look through repository history to find the most recent version of <formula> and
create a copy in <tap>`/Formula/`<formula>`@`<version>`.rb`. If the tap is not
@ -95,7 +96,7 @@ module Homebrew
switch "-f", "--force",
description: "Overwrite the destination formula if it already exists."
named_args :formula, number: 2
named_args number: 2
end
end

View File

@ -898,7 +898,6 @@ _brew_extract() {
return
;;
esac
__brew_complete_formulae
}
_brew_fetch() {

View File

@ -1019,7 +1019,7 @@ or open the Homebrew repository for editing if no formula is provided.
* `--cask`:
Treat all named arguments as casks.
### `extract` [*`--version`*`=`] [*`--force`*] *`formula`* ...
### `extract` [*`--version`*`=`] [*`--force`*] *`formula`* *`tap`*
Look through repository history to find the most recent version of *`formula`* and
create a copy in *`tap`*`/Formula/`*`formula`*`@`*`version`*`.rb`. If the tap is not

View File

@ -1417,7 +1417,7 @@ Treat all named arguments as formulae\.
\fB\-\-cask\fR
Treat all named arguments as casks\.
.
.SS "\fBextract\fR [\fI\-\-version\fR\fB=\fR] [\fI\-\-force\fR] \fIformula\fR \.\.\."
.SS "\fBextract\fR [\fI\-\-version\fR\fB=\fR] [\fI\-\-force\fR] \fIformula\fR \fItap\fR"
Look through repository history to find the most recent version of \fIformula\fR and create a copy in \fItap\fR\fB/Formula/\fR\fIformula\fR\fB@\fR\fIversion\fR\fB\.rb\fR\. If the tap is not installed yet, attempt to install/clone the tap before continuing\. To extract a formula from a tap that is not \fBhomebrew/core\fR use its fully\-qualified form of \fIuser\fR\fB/\fR\fIrepo\fR\fB/\fR\fIformula\fR\.
.
.TP