Skip to content
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

cmd/list: support listing formulae installed on request or automatically #17125

Merged
merged 12 commits into from
Apr 23, 2024
37 changes: 36 additions & 1 deletion Library/Homebrew/cmd/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require "cli/parser"
require "cask/list"
require "system_command"
require "tab"

module Homebrew
module Cmd
Expand Down Expand Up @@ -36,6 +37,11 @@
switch "--pinned",
description: "List only pinned formulae, or only the specified (pinned) " \
"formulae if <formula> are provided. See also `pin`, `unpin`."
switch "--installed-on-request",
description: "List the formulae installed on request."
switch "--installed-as-dependency",
description: "List the formulae installed as dependencies."

# passed through to ls
switch "-1",
description: "Force output to be one entry per line. " \
Expand All @@ -54,11 +60,18 @@
conflicts "--pinned", "--cask"
conflicts "--multiple", "--cask"
conflicts "--pinned", "--multiple"
["--installed-on-request", "--installed-as-dependency"].each do |flag|
conflicts "--cask", flag
conflicts "--versions", flag
conflicts "--pinned", flag
end
["-1", "-l", "-r", "-t"].each do |flag|
conflicts "--versions", flag
conflicts "--pinned", flag
end
["--versions", "--pinned", "-l", "-r", "-t"].each do |flag|
["--versions", "--pinned",
"---installed-on-request", "--installed-as-dependency",
"-l", "-r", "-t"].each do |flag|
conflicts "--full-name", flag
end

Expand Down Expand Up @@ -91,6 +104,28 @@
elsif args.versions?
filtered_list unless args.cask?
list_casks if args.cask? || (!args.formula? && !args.multiple? && args.no_named?)
elsif args.installed_on_request? || args.installed_as_dependency?
unless args.no_named?
raise UsageError,
"Cannot use `--installed-on-request` or " \
"`--installed-as-dependency` with formula arguments."
end

Formula.installed.sort.each do |formula|
tab = Tab.for_formula(formula)

Check warning on line 115 in Library/Homebrew/cmd/list.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/list.rb#L114-L115

Added lines #L114 - L115 were not covered by tests

if args.installed_on_request? && args.installed_as_dependency?

Check warning on line 117 in Library/Homebrew/cmd/list.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/list.rb#L117

Added line #L117 was not covered by tests
statuses = []
statuses << "installed on request" if tab.installed_on_request
statuses << "installed as dependency" if tab.installed_as_dependency
next if statuses.empty?

puts "#{formula.name}: #{statuses.join(", ")}"

Check warning on line 123 in Library/Homebrew/cmd/list.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/list.rb#L123

Added line #L123 was not covered by tests
elsif (args.installed_on_request? && tab.installed_on_request) ||
(args.installed_as_dependency? && tab.installed_as_dependency)
puts formula.name
end
end
elsif args.no_named?
ENV["CLICOLOR"] = nil

Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/list.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Library/Homebrew/test/sorbet/tapioca/compilers/args_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
describe "#args_table" do
it "returns a mapping of list args to default values" do
expect(compiler.args_table(list_parser).keys).to contain_exactly(
:"1?", :cask?, :casks?, :d?, :debug?, :formula?, :formulae?, :full_name?, :h?, :help?, :l?, :multiple?,
:pinned?, :q?, :quiet?, :r?, :t?, :v?, :verbose?, :versions?
:"1?", :cask?, :casks?, :d?, :debug?, :formula?, :formulae?,
:full_name?, :h?, :help?, :installed_as_dependency?,
:installed_on_request?, :l?, :multiple?, :pinned?,
:q?, :quiet?, :r?, :t?, :v?, :verbose?, :versions?
)
end

Expand Down
4 changes: 4 additions & 0 deletions completions/bash/brew
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,8 @@ _brew_list() {
--formula
--full-name
--help
--installed-as-dependency
--installed-on-request
--multiple
--pinned
--quiet
Expand Down Expand Up @@ -1522,6 +1524,8 @@ _brew_ls() {
--formula
--full-name
--help
--installed-as-dependency
--installed-on-request
--multiple
--pinned
--quiet
Expand Down
4 changes: 4 additions & 0 deletions completions/fish/brew.fish
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,8 @@ __fish_brew_complete_arg 'list' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'list' -l formula -d 'List only formulae, or treat all named arguments as formulae'
__fish_brew_complete_arg 'list' -l full-name -d 'Print formulae with fully-qualified names. Unless `--full-name`, `--versions` or `--pinned` are passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are passed to `ls`(1) which produces the actual output'
__fish_brew_complete_arg 'list' -l help -d 'Show this message'
__fish_brew_complete_arg 'list' -l installed-as-dependency -d 'List the formulae installed as dependencies'
__fish_brew_complete_arg 'list' -l installed-on-request -d 'List the formulae installed on request'
__fish_brew_complete_arg 'list' -l multiple -d 'Only show formulae with multiple versions installed'
__fish_brew_complete_arg 'list' -l pinned -d 'List only pinned formulae, or only the specified (pinned) formulae if formula are provided. See also `pin`, `unpin`'
__fish_brew_complete_arg 'list' -l quiet -d 'Make some output more quiet'
Expand Down Expand Up @@ -1061,6 +1063,8 @@ __fish_brew_complete_arg 'ls' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'ls' -l formula -d 'List only formulae, or treat all named arguments as formulae'
__fish_brew_complete_arg 'ls' -l full-name -d 'Print formulae with fully-qualified names. Unless `--full-name`, `--versions` or `--pinned` are passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are passed to `ls`(1) which produces the actual output'
__fish_brew_complete_arg 'ls' -l help -d 'Show this message'
__fish_brew_complete_arg 'ls' -l installed-as-dependency -d 'List the formulae installed as dependencies'
__fish_brew_complete_arg 'ls' -l installed-on-request -d 'List the formulae installed on request'
__fish_brew_complete_arg 'ls' -l multiple -d 'Only show formulae with multiple versions installed'
__fish_brew_complete_arg 'ls' -l pinned -d 'List only pinned formulae, or only the specified (pinned) formulae if formula are provided. See also `pin`, `unpin`'
__fish_brew_complete_arg 'ls' -l quiet -d 'Make some output more quiet'
Expand Down
20 changes: 12 additions & 8 deletions completions/zsh/_brew
Original file line number Diff line number Diff line change
Expand Up @@ -1232,13 +1232,15 @@ _brew_linkage() {
_brew_list() {
_arguments \
'--debug[Display any debugging information]' \
'(--versions --pinned --l --r --t)--full-name[Print formulae with fully-qualified names. Unless `--full-name`, `--versions` or `--pinned` are passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are passed to `ls`(1) which produces the actual output]' \
'(--versions --pinned ---installed-on-request --installed-as-dependency --l --r --t)--full-name[Print formulae with fully-qualified names. Unless `--full-name`, `--versions` or `--pinned` are passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are passed to `ls`(1) which produces the actual output]' \
'--help[Show this message]' \
'(--cask --versions --pinned --full-name)--installed-as-dependency[List the formulae installed as dependencies]' \
'(--cask --versions --pinned)--installed-on-request[List the formulae installed on request]' \
'(--cask --pinned)--multiple[Only show formulae with multiple versions installed]' \
'(--cask --multiple --1 --l --r --t --full-name)--pinned[List only pinned formulae, or only the specified (pinned) formulae if formula are provided. See also `pin`, `unpin`]' \
'(--cask --multiple --installed-on-request --installed-as-dependency --1 --l --r --t --full-name)--pinned[List only pinned formulae, or only the specified (pinned) formulae if formula are provided. See also `pin`, `unpin`]' \
'--quiet[Make some output more quiet]' \
'--verbose[Make some output more verbose]' \
'(--1 --l --r --t --full-name)--versions[Show the version number for installed formulae, or only the specified formulae if formula are provided]' \
'(--installed-on-request --installed-as-dependency --1 --l --r --t --full-name)--versions[Show the version number for installed formulae, or only the specified formulae if formula are provided]' \
'-1[Force output to be one entry per line. This is the default when output is not to a terminal]' \
'-l[List formulae and/or casks in long format. Has no effect when a formula or cask name is passed as an argument]' \
'-r[Reverse the order of the formulae and/or casks sort to list the oldest entries first. Has no effect when a formula or cask name is passed as an argument]' \
Expand All @@ -1247,7 +1249,7 @@ _brew_list() {
'(--cask)--formula[List only formulae, or treat all named arguments as formulae]' \
'*::installed_formula:__brew_installed_formulae' \
- installed_cask \
'(--formula --pinned --multiple)--cask[List only casks, or treat all named arguments as casks]' \
'(--formula --pinned --multiple --installed-on-request --installed-as-dependency)--cask[List only casks, or treat all named arguments as casks]' \
'*::installed_cask:__brew_installed_casks'
}

Expand Down Expand Up @@ -1313,13 +1315,15 @@ _brew_log() {
_brew_ls() {
_arguments \
'--debug[Display any debugging information]' \
'(--versions --pinned --l --r --t)--full-name[Print formulae with fully-qualified names. Unless `--full-name`, `--versions` or `--pinned` are passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are passed to `ls`(1) which produces the actual output]' \
'(--versions --pinned ---installed-on-request --installed-as-dependency --l --r --t)--full-name[Print formulae with fully-qualified names. Unless `--full-name`, `--versions` or `--pinned` are passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are passed to `ls`(1) which produces the actual output]' \
'--help[Show this message]' \
'(--cask --versions --pinned --full-name)--installed-as-dependency[List the formulae installed as dependencies]' \
'(--cask --versions --pinned)--installed-on-request[List the formulae installed on request]' \
'(--cask --pinned)--multiple[Only show formulae with multiple versions installed]' \
'(--cask --multiple --1 --l --r --t --full-name)--pinned[List only pinned formulae, or only the specified (pinned) formulae if formula are provided. See also `pin`, `unpin`]' \
'(--cask --multiple --installed-on-request --installed-as-dependency --1 --l --r --t --full-name)--pinned[List only pinned formulae, or only the specified (pinned) formulae if formula are provided. See also `pin`, `unpin`]' \
'--quiet[Make some output more quiet]' \
'--verbose[Make some output more verbose]' \
'(--1 --l --r --t --full-name)--versions[Show the version number for installed formulae, or only the specified formulae if formula are provided]' \
'(--installed-on-request --installed-as-dependency --1 --l --r --t --full-name)--versions[Show the version number for installed formulae, or only the specified formulae if formula are provided]' \
'-1[Force output to be one entry per line. This is the default when output is not to a terminal]' \
'-l[List formulae and/or casks in long format. Has no effect when a formula or cask name is passed as an argument]' \
'-r[Reverse the order of the formulae and/or casks sort to list the oldest entries first. Has no effect when a formula or cask name is passed as an argument]' \
Expand All @@ -1328,7 +1332,7 @@ _brew_ls() {
'(--cask)--formula[List only formulae, or treat all named arguments as formulae]' \
'*::installed_formula:__brew_installed_formulae' \
- installed_cask \
'(--formula --pinned --multiple)--cask[List only casks, or treat all named arguments as casks]' \
'(--formula --pinned --multiple --installed-on-request --installed-as-dependency)--cask[List only casks, or treat all named arguments as casks]' \
'*::installed_cask:__brew_installed_casks'
}

Expand Down
8 changes: 8 additions & 0 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,14 @@ paths within its current keg. If *`cask`* is provided, list its artifacts.
: List only pinned formulae, or only the specified (pinned) formulae if
*`formula`* are provided. See also `pin`, `unpin`.

`--installed-on-request`

: List the formulae installed on request.

`--installed-as-dependency`

: List the formulae installed as dependencies.

`-1`

: Force output to be one entry per line. This is the default when output is not
Expand Down
6 changes: 6 additions & 0 deletions manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ Only show formulae with multiple versions installed\.
\fB\-\-pinned\fP
List only pinned formulae, or only the specified (pinned) formulae if \fIformula\fP are provided\. See also \fBpin\fP, \fBunpin\fP\&\.
.TP
\fB\-\-installed\-on\-request\fP
List the formulae installed on request\.
.TP
\fB\-\-installed\-as\-dependency\fP
List the formulae installed as dependencies\.
.TP
\fB\-1\fP
Force output to be one entry per line\. This is the default when output is not to a terminal\.
.TP
Expand Down