Skip to content

Commit ab1c3ed

Browse files
Merge pull request #20044 from Homebrew/show-env-var-associations
parser: show related environment variable in switch description
2 parents 317110f + 3dc9e88 commit ab1c3ed

File tree

23 files changed

+241
-226
lines changed

23 files changed

+241
-226
lines changed

Library/Homebrew/cli/parser.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,15 @@ def switch(*names, description: nil, replacement: nil, env: nil, depends_on: nil
208208
return if global_switch
209209

210210
description = option_description(description, *names, hidden:)
211-
process_option(*names, description, type: :switch, hidden:) unless disable
212-
211+
env, counterpart = env
212+
if env && @non_global_processed_options.any?
213+
affix = counterpart ? " and `#{counterpart}` is passed." : "."
214+
description += " Enabled by default if `$HOMEBREW_#{env.upcase}` is set#{affix}"
215+
end
213216
if replacement || disable
214217
description += " (#{disable ? "disabled" : "deprecated"}#{"; replaced by #{replacement}" if replacement})"
215218
end
219+
process_option(*names, description, type: :switch, hidden:) unless disable
216220

217221
@parser.public_send(method, *names, *wrap_option_desc(description)) do |value|
218222
# This odeprecated should stick around indefinitely.

Library/Homebrew/cmd/bundle.rb

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ class Bundle < AbstractCommand
7373
description: "`install` prints output from commands as they are run. " \
7474
"`check` lists all missing dependencies."
7575
switch "--no-upgrade",
76-
env: :bundle_no_upgrade,
7776
description: "`install` does not run `brew upgrade` on outdated dependencies. " \
7877
"`check` does not check for outdated dependencies. " \
79-
"Note they may still be upgraded by `brew install` if needed. " \
80-
"This is enabled by default if `$HOMEBREW_BUNDLE_NO_UPGRADE` is set."
78+
"Note they may still be upgraded by `brew install` if needed.",
79+
env: :bundle_no_upgrade
8180
switch "--upgrade",
8281
description: "`install` runs `brew upgrade` on outdated dependencies, " \
8382
"even if `$HOMEBREW_BUNDLE_NO_UPGRADE` is set."
@@ -87,18 +86,15 @@ class Bundle < AbstractCommand
8786
switch "--install",
8887
description: "Run `install` before continuing to other operations e.g. `exec`."
8988
switch "--services",
90-
env: :bundle_services,
91-
description: "Temporarily start services while running the `exec` or `sh` command. " \
92-
"This is enabled by default if `$HOMEBREW_BUNDLE_SERVICES` is set."
89+
description: "Temporarily start services while running the `exec` or `sh` command.",
90+
env: :bundle_services
9391
switch "-f", "--force",
9492
description: "`install` runs with `--force`/`--overwrite`. " \
9593
"`dump` overwrites an existing `Brewfile`. " \
9694
"`cleanup` actually performs its cleanup operations."
9795
switch "--cleanup",
98-
env: :bundle_install_cleanup,
99-
description: "`install` performs cleanup operation, same as running `cleanup --force`. " \
100-
"This is enabled by default if `$HOMEBREW_BUNDLE_INSTALL_CLEANUP` is set and " \
101-
"`--global` is passed."
96+
description: "`install` performs cleanup operation, same as running `cleanup --force`.",
97+
env: [:bundle_install_cleanup, "--global"]
10298
switch "--all",
10399
description: "`list` all dependencies."
104100
switch "--formula", "--brews",
@@ -114,14 +110,12 @@ class Bundle < AbstractCommand
114110
switch "--vscode",
115111
description: "`list`, `dump` or `cleanup` VSCode (and forks/variants) extensions."
116112
switch "--no-vscode",
117-
env: :bundle_dump_no_vscode,
118-
description: "`dump` without VSCode (and forks/variants) extensions. " \
119-
"This is enabled by default if `$HOMEBREW_BUNDLE_DUMP_NO_VSCODE` is set."
113+
description: "`dump` without VSCode (and forks/variants) extensions.",
114+
env: :bundle_dump_no_vscode
120115
switch "--describe",
121-
env: :bundle_dump_describe,
122116
description: "`dump` adds a description comment above each line, unless the " \
123-
"dependency does not have a description. " \
124-
"This is enabled by default if `$HOMEBREW_BUNDLE_DUMP_DESCRIBE` is set."
117+
"dependency does not have a description.",
118+
env: :bundle_dump_describe
125119
switch "--no-restart",
126120
description: "`dump` does not add `restart_service` to formula lines."
127121
switch "--zap",

Library/Homebrew/cmd/install.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class InstallCmd < AbstractCommand
3333
description: "If brewing fails, open an interactive debugging session with access to IRB " \
3434
"or a shell inside the temporary build directory."
3535
switch "--display-times",
36-
env: :display_install_times,
37-
description: "Print install times for each package at the end of the run."
36+
description: "Print install times for each package at the end of the run.",
37+
env: :display_install_times
3838
switch "-f", "--force",
3939
description: "Install formulae without checking for previously installed keg-only or " \
4040
"non-migrated versions. When installing casks, overwrite existing files " \
@@ -44,9 +44,9 @@ class InstallCmd < AbstractCommand
4444
switch "-n", "--dry-run",
4545
description: "Show what would be installed, but do not actually install anything."
4646
switch "--ask",
47-
env: :ask,
4847
description: "Ask for confirmation before downloading and installing formulae. " \
49-
"Print bottles and dependencies download size and install size."
48+
"Print download and install sizes of bottles and dependencies.",
49+
env: :ask
5050
[
5151
[:switch, "--formula", "--formulae", {
5252
description: "Treat all named arguments as formulae.",

Library/Homebrew/cmd/outdated.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ class Outdated < AbstractCommand
3232
"formula is outdated. Otherwise, the repository's HEAD will only be checked for " \
3333
"updates when a new stable or development version has been released."
3434
switch "-g", "--greedy",
35-
env: :upgrade_greedy,
36-
description: "Also include outdated casks with `auto_updates true` or `version :latest`."
37-
35+
description: "Also include outdated casks with `auto_updates true` or `version :latest`.",
36+
env: :upgrade_greedy
3837
switch "--greedy-latest",
3938
description: "Also include outdated casks including those with `version :latest`."
40-
4139
switch "--greedy-auto-updates",
4240
description: "Also include outdated casks including those with `auto_updates true`."
4341

Library/Homebrew/cmd/reinstall.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ class Reinstall < AbstractCommand
3232
description: "If brewing fails, open an interactive debugging session with access to IRB " \
3333
"or a shell inside the temporary build directory."
3434
switch "--display-times",
35-
env: :display_install_times,
36-
description: "Print install times for each package at the end of the run."
35+
description: "Print install times for each package at the end of the run.",
36+
env: :display_install_times
3737
switch "-f", "--force",
3838
description: "Install without checking for previously installed keg-only or " \
3939
"non-migrated versions."
4040
switch "-v", "--verbose",
4141
description: "Print the verification and post-install steps."
4242
switch "--ask",
4343
description: "Ask for confirmation before downloading and upgrading formulae. " \
44-
"Print bottles and dependencies download size, install and net install size.",
44+
"Print download, install and net install sizes of bottles and dependencies.",
4545
env: :ask
4646
[
4747
[:switch, "--formula", "--formulae", { description: "Treat all named arguments as formulae." }],

Library/Homebrew/cmd/shellenv.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ class Shellenv < AbstractCommand
1313
description <<~EOS
1414
Valid shells: bash|csh|fish|pwsh|sh|tcsh|zsh
1515
16-
Print export statements. When run in a shell, this installation of Homebrew will be added to your `PATH`, `MANPATH`, and `INFOPATH`.
16+
Print export statements. When run in a shell, this installation of Homebrew will be added to your
17+
`$PATH`, `$MANPATH`, and `$INFOPATH`.
1718
1819
The variables `$HOMEBREW_PREFIX`, `$HOMEBREW_CELLAR` and `$HOMEBREW_REPOSITORY` are also exported to avoid
1920
querying them multiple times.
2021
To help guarantee idempotence, this command produces no output when Homebrew's `bin` and `sbin` directories
21-
are first and second respectively in your `PATH`. Consider adding evaluation of this command's output to
22+
are first and second respectively in your `$PATH`. Consider adding evaluation of this command's output to
2223
your dotfiles (e.g. `~/.bash_profile` or ~/.zprofile` on macOS and ~/.bashrc` or ~/.zshrc` on Linux) with:
2324
`eval "$(brew shellenv)"`
2425
2526
The shell can be specified explicitly with a supported shell name parameter. Unknown shells will output
2627
POSIX exports.
2728
EOS
29+
2830
named_args :shell
2931
end
3032
end

Library/Homebrew/cmd/upgrade.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class UpgradeCmd < AbstractCommand
2929
description: "If brewing fails, open an interactive debugging session with access to IRB " \
3030
"or a shell inside the temporary build directory."
3131
switch "--display-times",
32-
env: :display_install_times,
33-
description: "Print install times for each package at the end of the run."
32+
description: "Print install times for each package at the end of the run.",
33+
env: :display_install_times
3434
switch "-f", "--force",
3535
description: "Install formulae without checking for previously installed keg-only or " \
3636
"non-migrated versions. When installing casks, overwrite existing files " \
@@ -41,7 +41,7 @@ class UpgradeCmd < AbstractCommand
4141
description: "Show what would be upgraded, but do not actually upgrade anything."
4242
switch "--ask",
4343
description: "Ask for confirmation before downloading and upgrading formulae. " \
44-
"Print bottles and dependencies download size, install and net install size.",
44+
"Print download, install and net install sizes of bottles and dependencies.",
4545
env: :ask
4646
[
4747
[:switch, "--formula", "--formulae", {

Library/Homebrew/dev-cmd/audit.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Audit < AbstractCommand
4343
description: "Only check formulae and casks that are currently installed."
4444
switch "--eval-all",
4545
description: "Evaluate all available formulae and casks, whether installed or not, to audit them. " \
46-
"Implied if `HOMEBREW_EVAL_ALL` is set."
46+
"Implied if `$HOMEBREW_EVAL_ALL` is set."
4747
switch "--new",
4848
description: "Run various additional style checks to determine if a new formula or cask is eligible " \
4949
"for Homebrew. This should be used when creating new formulae or casks and implies " \

Library/Homebrew/dev-cmd/bump.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def run
118118
else
119119
raise UsageError,
120120
"`brew bump` without named arguments needs `--installed` or `--eval-all` passed or " \
121-
"`HOMEBREW_EVAL_ALL` set!"
121+
"`$HOMEBREW_EVAL_ALL` set!"
122122
end
123123

124124
if args.start_with

Library/Homebrew/dev-cmd/determine-test-runners.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class DetermineTestRunners < AbstractCommand
2121
"dependents.",
2222
env: :eval_all
2323
switch "--dependents",
24-
description: "Determine runners for testing dependents. Requires `--eval-all` or `HOMEBREW_EVAL_ALL`.",
24+
description: "Determine runners for testing dependents. " \
25+
"Requires `--eval-all` or `$HOMEBREW_EVAL_ALL` to be set.",
2526
depends_on: "--eval-all"
2627

2728
named_args max: 2

0 commit comments

Comments
 (0)