cmd/bump: add --installed flag

This allows users to only try to bump formulae and casks they
currently have installed. It copies this behavior from the
livecheck command.
This commit is contained in:
apainintheneck 2023-08-05 09:51:54 -07:00
parent 3eb48a828d
commit 0979f7c35f
6 changed files with 37 additions and 19 deletions

View File

@ -35,6 +35,8 @@ module Homebrew
description: "Check only formulae." description: "Check only formulae."
switch "--cask", "--casks", switch "--cask", "--casks",
description: "Check only casks." description: "Check only casks."
switch "--installed",
description: "Check formulae and casks that are currently installed."
switch "--open-pr", switch "--open-pr",
description: "Open a pull request for the new version if none have been opened yet." description: "Open a pull request for the new version if none have been opened yet."
flag "--limit=", flag "--limit=",
@ -60,13 +62,21 @@ module Homebrew
raise UsageError, "`--limit` must be used with either `--formula` or `--cask`." raise UsageError, "`--limit` must be used with either `--formula` or `--cask`."
end end
formulae_and_casks = if args.formula? Homebrew.with_no_api_env do
formulae_and_casks = if args.installed?
formulae = args.cask? ? [] : Formula.installed
casks = args.formula? ? [] : Cask::Caskroom.casks
formulae + casks
elsif args.named.present?
if args.formula?
args.named.to_formulae args.named.to_formulae
elsif args.cask? elsif args.cask?
args.named.to_casks args.named.to_casks
else else
args.named.to_formulae_and_casks args.named.to_formulae_and_casks
end end
end
formulae_and_casks = formulae_and_casks&.sort_by do |formula_or_cask| formulae_and_casks = formulae_and_casks&.sort_by do |formula_or_cask|
formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
end end
@ -79,7 +89,6 @@ module Homebrew
end end
end end
Homebrew.with_no_api_env do
if formulae_and_casks.present? if formulae_and_casks.present?
handle_formula_and_casks(formulae_and_casks, args) handle_formula_and_casks(formulae_and_casks, args)
else else

View File

@ -441,6 +441,7 @@ _brew_bump() {
--formula --formula
--full-name --full-name
--help --help
--installed
--limit --limit
--no-pull-requests --no-pull-requests
--open-pr --open-pr

View File

@ -384,6 +384,7 @@ __fish_brew_complete_arg 'bump' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'bump' -l formula -d 'Check only formulae' __fish_brew_complete_arg 'bump' -l formula -d 'Check only formulae'
__fish_brew_complete_arg 'bump' -l full-name -d 'Print formulae/casks with fully-qualified names' __fish_brew_complete_arg 'bump' -l full-name -d 'Print formulae/casks with fully-qualified names'
__fish_brew_complete_arg 'bump' -l help -d 'Show this message' __fish_brew_complete_arg 'bump' -l help -d 'Show this message'
__fish_brew_complete_arg 'bump' -l installed -d 'Check formulae and casks that are currently installed'
__fish_brew_complete_arg 'bump' -l limit -d 'Limit number of package results returned' __fish_brew_complete_arg 'bump' -l limit -d 'Limit number of package results returned'
__fish_brew_complete_arg 'bump' -l no-pull-requests -d 'Do not retrieve pull requests from GitHub' __fish_brew_complete_arg 'bump' -l no-pull-requests -d 'Do not retrieve pull requests from GitHub'
__fish_brew_complete_arg 'bump' -l open-pr -d 'Open a pull request for the new version if none have been opened yet' __fish_brew_complete_arg 'bump' -l open-pr -d 'Open a pull request for the new version if none have been opened yet'

View File

@ -495,6 +495,7 @@ _brew_bump() {
'--debug[Display any debugging information]' \ '--debug[Display any debugging information]' \
'--full-name[Print formulae/casks with fully-qualified names]' \ '--full-name[Print formulae/casks with fully-qualified names]' \
'--help[Show this message]' \ '--help[Show this message]' \
'--installed[Check formulae and casks that are currently installed]' \
'--limit[Limit number of package results returned]' \ '--limit[Limit number of package results returned]' \
'(--open-pr)--no-pull-requests[Do not retrieve pull requests from GitHub]' \ '(--open-pr)--no-pull-requests[Do not retrieve pull requests from GitHub]' \
'(--no-pull-requests)--open-pr[Open a pull request for the new version if none have been opened yet]' \ '(--no-pull-requests)--open-pr[Open a pull request for the new version if none have been opened yet]' \

View File

@ -1012,6 +1012,8 @@ formulae, also displays whether a pull request has been opened with the URL.
Check only formulae. Check only formulae.
* `--cask`: * `--cask`:
Check only casks. Check only casks.
* `--installed`:
Check formulae and casks that are currently installed.
* `--open-pr`: * `--open-pr`:
Open a pull request for the new version if none have been opened yet. Open a pull request for the new version if none have been opened yet.
* `--limit`: * `--limit`:

View File

@ -1443,6 +1443,10 @@ Check only formulae\.
Check only casks\. Check only casks\.
. .
.TP .TP
\fB\-\-installed\fR
Check formulae and casks that are currently installed\.
.
.TP
\fB\-\-open\-pr\fR \fB\-\-open\-pr\fR
Open a pull request for the new version if none have been opened yet\. Open a pull request for the new version if none have been opened yet\.
. .