Make install/reinstall/upgrade options more consistent.

This commit is contained in:
Mike McQuaid 2019-01-29 19:25:13 +00:00
parent 22c2b06fa5
commit 9eabcdad7d
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
7 changed files with 203 additions and 53 deletions

View File

@ -148,6 +148,21 @@ module Homebrew
.gsub(/\*(.*?)\*/m, "#{Tty.underline}\\1#{Tty.reset}") .gsub(/\*(.*?)\*/m, "#{Tty.underline}\\1#{Tty.reset}")
end end
def formula_options
ARGV.formulae.each do |f|
next if f.options.empty?
f.options.each do |o|
name = o.flag
description = "`#{f.name}`: #{o.description}"
if name.end_with? "="
flag name, description: description
else
switch name, description: description
end
end
end
end
private private
def enable_switch(*names) def enable_switch(*names)

View File

@ -41,7 +41,7 @@
#: If `--devel` is passed, and <formula> defines it, install the development version. #: If `--devel` is passed, and <formula> defines it, install the development version.
#: #:
#: If `--HEAD` is passed, and <formula> defines it, install the HEAD version, #: If `--HEAD` is passed, and <formula> defines it, install the HEAD version,
#: aka master, trunk, unstable. #: aka. master, trunk, unstable.
#: #:
#: If `--keep-tmp` is passed, the temporary files created during installation #: If `--keep-tmp` is passed, the temporary files created during installation
#: are not deleted. #: are not deleted.
@ -85,7 +85,7 @@ module Homebrew
def install_args def install_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS
`install` [<options>] formula `install` [<options>] <formula>
Install <formula>. Install <formula>.
@ -124,7 +124,7 @@ module Homebrew
switch "--devel", switch "--devel",
description: "If <formula> defines it, install the development version." description: "If <formula> defines it, install the development version."
switch "--HEAD", switch "--HEAD",
description: "If <formula> defines it, install the HEAD version, aka master, trunk, unstable." description: "If <formula> defines it, install the HEAD version, aka. master, trunk, unstable."
switch "--fetch-HEAD", switch "--fetch-HEAD",
description: "Fetch the upstream repository to detect if the HEAD installation of the "\ description: "Fetch the upstream repository to detect if the HEAD installation of the "\
"formula is outdated. Otherwise, the repository's HEAD will be checked for "\ "formula is outdated. Otherwise, the repository's HEAD will be checked for "\
@ -146,19 +146,7 @@ module Homebrew
"package into a Homebrew package." "package into a Homebrew package."
switch "-g", "--git", switch "-g", "--git",
description: "Create a Git repository, useful for creating patches to the software." description: "Create a Git repository, useful for creating patches to the software."
formula_options
ARGV.formulae.each do |f|
next if f.options.empty?
f.options.each do |o|
name = o.flag
description = "`#{f.name}`: #{o.description}"
if name.end_with? "="
flag name, description: description
else
switch name, description: description
end
end
end
end end
end end

View File

@ -1,8 +1,30 @@
#: * `reinstall` [`--display-times`] <formula>: #: * `reinstall` [`--debug`] [`--build-from-source`|`--force-bottle`] [`--keep-tmp`] [`--force`] [`--verbose`] [`--display-times`] <formula>:
#: Uninstall and then install <formula> (with existing install options). #: Uninstall and then install <formula> (with existing and any appended install options).
#:
#: If `--debug` (or `-d`) is passed and brewing fails, open an interactive debugging
#: session with access to IRB or a shell inside the temporary build directory.
#:
#: If `--build-from-source` (or `-s`) is passed, compile the specified <formula> from
#: source even if a bottle is provided. Dependencies will still be installed
#: from bottles if they are available.
#:
#: If `--force-bottle` is passed, install from a bottle if it exists for the
#: current or newest version of macOS, even if it would not normally be used
#: for installation.
#:
#: If `--keep-tmp` is passed, the temporary files created during installation
#: are not deleted.
#:
#: If `--force` (or `-f`) is passed, install without checking for previously
#: installed keg-only or non-migrated versions
#:
#: If `--verbose` (or `-v`) is passed, print the verification and postinstall steps.
#: #:
#: If `--display-times` is passed, install times for each formula are printed #: If `--display-times` is passed, install times for each formula are printed
#: at the end of the run. #: at the end of the run.
#:
#: Installation options specific to <formula> may be appended to the command,
#: and can be listed with `brew options` <formula>.
require "formula_installer" require "formula_installer"
require "development_tools" require "development_tools"
@ -17,16 +39,28 @@ module Homebrew
def reinstall_args def reinstall_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS
`reinstall` [<option(s)>] <formula>: `reinstall` [<options>] <formula>
Uninstall and then install <formula> (with existing install options). Uninstall and then install <formula> (with existing and any appended install options).
EOS EOS
switch :debug,
description: "If brewing fails, open an interactive debugging session with access to IRB "\
"or a shell inside the temporary build directory"
switch "-s", "--build-from-source", switch "-s", "--build-from-source",
description: "Compile the formula> from source even if a bottle is available." description: "Compile <formula> from source even if a bottle is available."
switch "--force-bottle",
description: "Install from a bottle if it exists for the current or newest version of "\
"macOS, even if it would not normally be used for installation."
switch "--keep-tmp",
description: "Dont delete the temporary files created during installation."
switch :force,
description: "Install without checking for previously installed keg-only or "\
"non-migrated versions."
switch :verbose,
description: "Print the verification and postinstall steps."
switch "--display-times", switch "--display-times",
description: "Print install times for each formula at the end of the run." description: "Print install times for each formula at the end of the run."
switch :verbose formula_options
switch :debug
end end
end end

View File

@ -1,7 +1,19 @@
#: * `upgrade` [<install-options>] [`--fetch-HEAD`] [`--ignore-pinned`] [`--display-times`] [<formulae>]: #: * `upgrade` [`--debug`] [`--build-from-source`|`--force-bottle`] [`--fetch-HEAD`] [`--ignore-pinned`] [`--keep-tmp`] [`--force`] [`--verbose`] [`--display-times`] [<formula>] [<options> ...]:
#: Upgrade outdated, unpinned brews (with existing install options). #: Upgrade outdated, unpinned brews (with existing and any appended install options).
#: #:
#: Options for the `install` command are also valid here. #: If <formula> are given, upgrade only the specified brews (unless they
#: are pinned; see `pin`, `unpin`).
#:
#: If `--debug` (or `-d`) is passed and brewing fails, open an interactive debugging
#: session with access to IRB or a shell inside the temporary build directory.
#:
#: If `--build-from-source` (or `-s`) is passed, compile the specified <formula> from
#: source even if a bottle is provided. Dependencies will still be installed
#: from bottles if they are available.
#:
#: If `--force-bottle` is passed, install from a bottle if it exists for the
#: current or newest version of macOS, even if it would not normally be used
#: for installation.
#: #:
#: If `--fetch-HEAD` is passed, fetch the upstream repository to detect if #: If `--fetch-HEAD` is passed, fetch the upstream repository to detect if
#: the HEAD installation of the formula is outdated. Otherwise, the #: the HEAD installation of the formula is outdated. Otherwise, the
@ -11,11 +23,19 @@
#: If `--ignore-pinned` is passed, set a 0 exit code even if pinned formulae #: If `--ignore-pinned` is passed, set a 0 exit code even if pinned formulae
#: are not upgraded. #: are not upgraded.
#: #:
#: If `--keep-tmp` is passed, the temporary files created during installation
#: are not deleted.
#:
#: If `--force` (or `-f`) is passed, install without checking for previously
#: installed keg-only or non-migrated versions
#:
#: If `--verbose` (or `-v`) is passed, print the verification and postinstall steps.
#:
#: If `--display-times` is passed, install times for each formula are printed #: If `--display-times` is passed, install times for each formula are printed
#: at the end of the run. #: at the end of the run.
#: #:
#: If <formulae> are given, upgrade only the specified brews (unless they #: Additional options specific to <formula> may be appended to the command,
#: are pinned; see `pin`, `unpin`). #: and can be listed with `brew options` <formula>.
require "install" require "install"
require "reinstall" require "reinstall"
@ -31,26 +51,37 @@ module Homebrew
def upgrade_args def upgrade_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
usage_banner <<~EOS usage_banner <<~EOS
`upgrade` [<install-options>] [<options>] [<formulae>] `upgrade` [<options>] <formula>
Upgrade outdated, unpinned brews (with existing install options). Upgrade outdated, unpinned brews (with existing and any appended install options).
Options for the `install` command are also valid here.
If <formulae> are given, upgrade only the specified brews (unless they If <formula> are given, upgrade only the specified brews (unless they
are pinned; see `pin`, `unpin`). are pinned; see `pin`, `unpin`).
EOS EOS
switch :debug,
description: "If brewing fails, open an interactive debugging session with access to IRB "\
"or a shell inside the temporary build directory"
switch "-s", "--build-from-source",
description: "Compile <formula> from source even if a bottle is available."
switch "--force-bottle",
description: "Install from a bottle if it exists for the current or newest version of "\
"macOS, even if it would not normally be used for installation."
switch "--fetch-HEAD", switch "--fetch-HEAD",
description: "Fetch the upstream repository to detect if the HEAD installation of the "\ description: "Fetch the upstream repository to detect if the HEAD installation of the "\
"formula is outdated. Otherwise, the repository's HEAD will be checked for "\ "formula is outdated. Otherwise, the repository's HEAD will be checked for "\
"updates when a new stable or devel version has been released." "updates when a new stable or devel version has been released."
switch "--ignore-pinned", switch "--ignore-pinned",
description: "Set a 0 exit code even if pinned formulae are not upgraded." description: "Set a 0 exit code even if pinned formulae are not upgraded."
switch "--build-bottle", switch "--keep-tmp",
description: "Prepare the formula for eventual bottling during installation." description: "Dont delete the temporary files created during installation."
switch :force,
description: "Install without checking for previously installed keg-only or "\
"non-migrated versions."
switch :verbose,
description: "Print the verification and postinstall steps."
switch "--display-times", switch "--display-times",
description: "Print install times for each formula at the end of the run." description: "Print install times for each formula at the end of the run."
switch :verbose formula_options
switch :debug
end end
end end

View File

@ -21,8 +21,9 @@ describe "brew reinstall", :integration_test do
end end
it "reinstalls a Formula even when one of the options is invalid" do it "reinstalls a Formula even when one of the options is invalid" do
expect { brew "reinstall", "testball", "--with-fo" } expect { brew "reinstall", "testball", "--invalid" }
.to output(/Error: invalid option: --with-fo/).to_stderr .to output(/Error: invalid option: --invalid/).to_stderr
.and not_to_output.to_stdout
.and be_a_failure .and be_a_failure
end end

View File

@ -279,7 +279,7 @@ these flags should only appear after a command.
If `--devel` is passed, and *`formula`* defines it, install the development version. If `--devel` is passed, and *`formula`* defines it, install the development version.
If `--HEAD` is passed, and *`formula`* defines it, install the HEAD version, If `--HEAD` is passed, and *`formula`* defines it, install the HEAD version,
aka master, trunk, unstable. aka. master, trunk, unstable.
If `--keep-tmp` is passed, the temporary files created during installation If `--keep-tmp` is passed, the temporary files created during installation
are not deleted. are not deleted.
@ -414,12 +414,34 @@ these flags should only appear after a command.
If `--syntax` is passed, also syntax-check all of Homebrew's Ruby files. If `--syntax` is passed, also syntax-check all of Homebrew's Ruby files.
* `reinstall` [`--display-times`] *`formula`*: * `reinstall` [`--debug`] [`--build-from-source`|`--force-bottle`] [`--keep-tmp`] [`--force`] [`--verbose`] [`--display-times`] *`formula`*:
Uninstall and then install *`formula`* (with existing install options). Uninstall and then install *`formula`* (with existing and any appended install options).
If `--debug` (or `-d`) is passed and brewing fails, open an interactive debugging
session with access to IRB or a shell inside the temporary build directory.
If `--build-from-source` (or `-s`) is passed, compile the specified *`formula`* from
source even if a bottle is provided. Dependencies will still be installed
from bottles if they are available.
If `--force-bottle` is passed, install from a bottle if it exists for the
current or newest version of macOS, even if it would not normally be used
for installation.
If `--keep-tmp` is passed, the temporary files created during installation
are not deleted.
If `--force` (or `-f`) is passed, install without checking for previously
installed keg-only or non-migrated versions
If `--verbose` (or `-v`) is passed, print the verification and postinstall steps.
If `--display-times` is passed, install times for each formula are printed If `--display-times` is passed, install times for each formula are printed
at the end of the run. at the end of the run.
Installation options specific to *`formula`* may be appended to the command,
and can be listed with `brew options` *`formula`*.
* `search`, `-S`: * `search`, `-S`:
Display all locally available formulae (including tapped ones). Display all locally available formulae (including tapped ones).
No online search is performed. No online search is performed.
@ -588,10 +610,22 @@ these flags should only appear after a command.
`repositories`) using `git`(1) to their latest `origin/master`. Note this `repositories`) using `git`(1) to their latest `origin/master`. Note this
will destroy all your uncommitted or committed changes. will destroy all your uncommitted or committed changes.
* `upgrade` [*`install-options`*] [`--fetch-HEAD`] [`--ignore-pinned`] [`--display-times`] [*`formulae`*]: * `upgrade` [`--debug`] [`--build-from-source`|`--force-bottle`] [`--fetch-HEAD`] [`--ignore-pinned`] [`--keep-tmp`] [`--force`] [`--verbose`] [`--display-times`] [*`formula`*] [*`options`* ...]:
Upgrade outdated, unpinned brews (with existing install options). Upgrade outdated, unpinned brews (with existing and any appended install options).
Options for the `install` command are also valid here. If *`formula`* are given, upgrade only the specified brews (unless they
are pinned; see `pin`, `unpin`).
If `--debug` (or `-d`) is passed and brewing fails, open an interactive debugging
session with access to IRB or a shell inside the temporary build directory.
If `--build-from-source` (or `-s`) is passed, compile the specified *`formula`* from
source even if a bottle is provided. Dependencies will still be installed
from bottles if they are available.
If `--force-bottle` is passed, install from a bottle if it exists for the
current or newest version of macOS, even if it would not normally be used
for installation.
If `--fetch-HEAD` is passed, fetch the upstream repository to detect if If `--fetch-HEAD` is passed, fetch the upstream repository to detect if
the HEAD installation of the formula is outdated. Otherwise, the the HEAD installation of the formula is outdated. Otherwise, the
@ -601,11 +635,19 @@ these flags should only appear after a command.
If `--ignore-pinned` is passed, set a 0 exit code even if pinned formulae If `--ignore-pinned` is passed, set a 0 exit code even if pinned formulae
are not upgraded. are not upgraded.
If `--keep-tmp` is passed, the temporary files created during installation
are not deleted.
If `--force` (or `-f`) is passed, install without checking for previously
installed keg-only or non-migrated versions
If `--verbose` (or `-v`) is passed, print the verification and postinstall steps.
If `--display-times` is passed, install times for each formula are printed If `--display-times` is passed, install times for each formula are printed
at the end of the run. at the end of the run.
If *`formulae`* are given, upgrade only the specified brews (unless they Additional options specific to *`formula`* may be appended to the command,
are pinned; see `pin`, `unpin`). and can be listed with `brew options` *`formula`*.
* `uses` [`--installed`] [`--recursive`] [`--include-build`] [`--include-test`] [`--include-optional`] [`--skip-recommended`] [`--devel`|`--HEAD`] *`formulae`*: * `uses` [`--installed`] [`--recursive`] [`--include-build`] [`--include-test`] [`--include-optional`] [`--skip-recommended`] [`--devel`|`--HEAD`] *`formulae`*:
Show the formulae that specify *`formulae`* as a dependency. When given Show the formulae that specify *`formulae`* as a dependency. When given

View File

@ -285,7 +285,7 @@ If \fB\-\-include\-test\fR is passed, install testing dependencies\. These are o
If \fB\-\-devel\fR is passed, and \fIformula\fR defines it, install the development version\. If \fB\-\-devel\fR is passed, and \fIformula\fR defines it, install the development version\.
. .
.IP .IP
If \fB\-\-HEAD\fR is passed, and \fIformula\fR defines it, install the HEAD version, aka master, trunk, unstable\. If \fB\-\-HEAD\fR is passed, and \fIformula\fR defines it, install the HEAD version, aka\. master, trunk, unstable\.
. .
.IP .IP
If \fB\-\-keep\-tmp\fR is passed, the temporary files created during installation are not deleted\. If \fB\-\-keep\-tmp\fR is passed, the temporary files created during installation are not deleted\.
@ -426,12 +426,33 @@ If \fB\-\-aliases\fR is passed, also verify any alias symlinks in each tap\.
If \fB\-\-syntax\fR is passed, also syntax\-check all of Homebrew\'s Ruby files\. If \fB\-\-syntax\fR is passed, also syntax\-check all of Homebrew\'s Ruby files\.
. .
.TP .TP
\fBreinstall\fR [\fB\-\-display\-times\fR] \fIformula\fR \fBreinstall\fR [\fB\-\-debug\fR] [\fB\-\-build\-from\-source\fR|\fB\-\-force\-bottle\fR] [\fB\-\-keep\-tmp\fR] [\fB\-\-force\fR] [\fB\-\-verbose\fR] [\fB\-\-display\-times\fR] \fIformula\fR
Uninstall and then install \fIformula\fR (with existing install options)\. Uninstall and then install \fIformula\fR (with existing and any appended install options)\.
.
.IP
If \fB\-\-debug\fR (or \fB\-d\fR) is passed and brewing fails, open an interactive debugging session with access to IRB or a shell inside the temporary build directory\.
.
.IP
If \fB\-\-build\-from\-source\fR (or \fB\-s\fR) is passed, compile the specified \fIformula\fR from source even if a bottle is provided\. Dependencies will still be installed from bottles if they are available\.
.
.IP
If \fB\-\-force\-bottle\fR is passed, install from a bottle if it exists for the current or newest version of macOS, even if it would not normally be used for installation\.
.
.IP
If \fB\-\-keep\-tmp\fR is passed, the temporary files created during installation are not deleted\.
.
.IP
If \fB\-\-force\fR (or \fB\-f\fR) is passed, install without checking for previously installed keg\-only or non\-migrated versions
.
.IP
If \fB\-\-verbose\fR (or \fB\-v\fR) is passed, print the verification and postinstall steps\.
. .
.IP .IP
If \fB\-\-display\-times\fR is passed, install times for each formula are printed at the end of the run\. If \fB\-\-display\-times\fR is passed, install times for each formula are printed at the end of the run\.
. .
.IP
Installation options specific to \fIformula\fR may be appended to the command, and can be listed with \fBbrew options\fR \fIformula\fR\.
.
.TP .TP
\fBsearch\fR, \fB\-S\fR \fBsearch\fR, \fB\-S\fR
Display all locally available formulae (including tapped ones)\. No online search is performed\. Display all locally available formulae (including tapped ones)\. No online search is performed\.
@ -601,11 +622,20 @@ If \fB\-\-force\fR (or \fB\-f\fR) is specified then always do a slower, full upd
Fetches and resets Homebrew and all tap repositories (or the specified \fBrepositories\fR) using \fBgit\fR(1) to their latest \fBorigin/master\fR\. Note this will destroy all your uncommitted or committed changes\. Fetches and resets Homebrew and all tap repositories (or the specified \fBrepositories\fR) using \fBgit\fR(1) to their latest \fBorigin/master\fR\. Note this will destroy all your uncommitted or committed changes\.
. .
.TP .TP
\fBupgrade\fR [\fIinstall\-options\fR] [\fB\-\-fetch\-HEAD\fR] [\fB\-\-ignore\-pinned\fR] [\fB\-\-display\-times\fR] [\fIformulae\fR] \fBupgrade\fR [\fB\-\-debug\fR] [\fB\-\-build\-from\-source\fR|\fB\-\-force\-bottle\fR] [\fB\-\-fetch\-HEAD\fR] [\fB\-\-ignore\-pinned\fR] [\fB\-\-keep\-tmp\fR] [\fB\-\-force\fR] [\fB\-\-verbose\fR] [\fB\-\-display\-times\fR] [\fIformula\fR] [\fIoptions\fR \.\.\.]
Upgrade outdated, unpinned brews (with existing install options)\. Upgrade outdated, unpinned brews (with existing and any appended install options)\.
. .
.IP .IP
Options for the \fBinstall\fR command are also valid here\. If \fIformula\fR are given, upgrade only the specified brews (unless they are pinned; see \fBpin\fR, \fBunpin\fR)\.
.
.IP
If \fB\-\-debug\fR (or \fB\-d\fR) is passed and brewing fails, open an interactive debugging session with access to IRB or a shell inside the temporary build directory\.
.
.IP
If \fB\-\-build\-from\-source\fR (or \fB\-s\fR) is passed, compile the specified \fIformula\fR from source even if a bottle is provided\. Dependencies will still be installed from bottles if they are available\.
.
.IP
If \fB\-\-force\-bottle\fR is passed, install from a bottle if it exists for the current or newest version of macOS, even if it would not normally be used for installation\.
. .
.IP .IP
If \fB\-\-fetch\-HEAD\fR is passed, fetch the upstream repository to detect if the HEAD installation of the formula is outdated\. Otherwise, the repository\'s HEAD will be checked for updates when a new stable or devel version has been released\. If \fB\-\-fetch\-HEAD\fR is passed, fetch the upstream repository to detect if the HEAD installation of the formula is outdated\. Otherwise, the repository\'s HEAD will be checked for updates when a new stable or devel version has been released\.
@ -614,10 +644,19 @@ If \fB\-\-fetch\-HEAD\fR is passed, fetch the upstream repository to detect if t
If \fB\-\-ignore\-pinned\fR is passed, set a 0 exit code even if pinned formulae are not upgraded\. If \fB\-\-ignore\-pinned\fR is passed, set a 0 exit code even if pinned formulae are not upgraded\.
. .
.IP .IP
If \fB\-\-keep\-tmp\fR is passed, the temporary files created during installation are not deleted\.
.
.IP
If \fB\-\-force\fR (or \fB\-f\fR) is passed, install without checking for previously installed keg\-only or non\-migrated versions
.
.IP
If \fB\-\-verbose\fR (or \fB\-v\fR) is passed, print the verification and postinstall steps\.
.
.IP
If \fB\-\-display\-times\fR is passed, install times for each formula are printed at the end of the run\. If \fB\-\-display\-times\fR is passed, install times for each formula are printed at the end of the run\.
. .
.IP .IP
If \fIformulae\fR are given, upgrade only the specified brews (unless they are pinned; see \fBpin\fR, \fBunpin\fR)\. Additional options specific to \fIformula\fR may be appended to the command, and can be listed with \fBbrew options\fR \fIformula\fR\.
. .
.TP .TP
\fBuses\fR [\fB\-\-installed\fR] [\fB\-\-recursive\fR] [\fB\-\-include\-build\fR] [\fB\-\-include\-test\fR] [\fB\-\-include\-optional\fR] [\fB\-\-skip\-recommended\fR] [\fB\-\-devel\fR|\fB\-\-HEAD\fR] \fIformulae\fR \fBuses\fR [\fB\-\-installed\fR] [\fB\-\-recursive\fR] [\fB\-\-include\-build\fR] [\fB\-\-include\-test\fR] [\fB\-\-include\-optional\fR] [\fB\-\-skip\-recommended\fR] [\fB\-\-devel\fR|\fB\-\-HEAD\fR] \fIformulae\fR