Merge pull request #8851 from Akylzhan/patch

cmd/list.rb: --formula and --cask as default option on TTY
This commit is contained in:
Mike McQuaid 2020-10-13 11:52:19 +01:00 committed by GitHub
commit a0a9fa241f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 11 deletions

View File

@ -34,9 +34,9 @@ module Homebrew
description: "Show the versions of pinned formulae, or only the specified (pinned) "\ description: "Show the versions of pinned formulae, or only the specified (pinned) "\
"formulae if <formula> are provided. See also `pin`, `unpin`." "formulae if <formula> are provided. See also `pin`, `unpin`."
switch "--formula", "--formulae", switch "--formula", "--formulae",
description: "List only formulae." description: "List only formulae. `This is the default action on non TTY.`"
switch "--cask", "--casks", switch "--cask", "--casks",
description: "List only casks." description: "List only casks, or <cask> if provided."
# passed through to ls # passed through to ls
switch "-1", switch "-1",
description: "Force output to be one entry per line. " \ description: "Force output to be one entry per line. " \
@ -87,7 +87,13 @@ module Homebrew
ls_args << "-r" if args.r? ls_args << "-r" if args.r?
ls_args << "-t" if args.t? ls_args << "-t" if args.t?
safe_system "ls", *ls_args, HOMEBREW_CELLAR if !$stdout.tty? && !args.formula?
odeprecated "`brew list` to only list formulae", "`brew list --formula`"
safe_system "ls", *ls_args, HOMEBREW_CELLAR
else
safe_system "ls", *ls_args, HOMEBREW_CELLAR
list_casks(args: args) unless args.formula?
end
end end
elsif args.verbose? || !$stdout.tty? elsif args.verbose? || !$stdout.tty?
system_command! "find", args: args.named.to_kegs.map(&:to_s) + %w[-not -type d -print], print_stdout: true system_command! "find", args: args.named.to_kegs.map(&:to_s) + %w[-not -type d -print], print_stdout: true

View File

@ -15,7 +15,7 @@ describe "brew list", :integration_test do
(HOMEBREW_CELLAR/f/"1.0/somedir").mkpath (HOMEBREW_CELLAR/f/"1.0/somedir").mkpath
end end
expect { brew "list" } expect { brew "list", "--formula" }
.to output("#{formulae.join("\n")}\n").to_stdout .to output("#{formulae.join("\n")}\n").to_stdout
.and not_to_output.to_stderr .and not_to_output.to_stderr
.and be_a_success .and be_a_success

View File

@ -62,10 +62,17 @@ __brew_formulae() {
__brew_installed_formulae() { __brew_installed_formulae() {
local -a formulae local -a formulae
formulae=($(brew list)) formulae=($(brew list --formula))
_describe -t formulae 'installed formulae' formulae _describe -t formulae 'installed formulae' formulae
} }
__brew_installed_casks() {
local -a list
local expl
list=( $(brew list --cask) )
_wanted list expl 'installed casks' compadd -a list
}
__brew_outdated_formulae() { __brew_outdated_formulae() {
local -a formulae local -a formulae
formulae=($(brew outdated)) formulae=($(brew outdated))
@ -493,11 +500,12 @@ _brew_linkage() {
# brew list, ls [--full-name]: # brew list, ls [--full-name]:
# brew list, ls --unbrewed: # brew list, ls --unbrewed:
# brew list, ls [--versions [--multiple]] [--pinned] [formulae]: # brew list, ls [--versions [--multiple]] [--pinned] [formulae]:
# brew list, ls --cask: # brew list, ls [--cask|--formula]:
_brew_list() { _brew_list() {
local state local state
_arguments \ _arguments \
- formulae \ - formulae \
'--formula[list install formulae]' \
'--full-name[print formulae with fully-qualified names]' \ '--full-name[print formulae with fully-qualified names]' \
'--unbrewed[files in brew --prefix not controlled by brew]' \ '--unbrewed[files in brew --prefix not controlled by brew]' \
'--pinned[list all versions of pinned formulae]' \ '--pinned[list all versions of pinned formulae]' \
@ -575,7 +583,7 @@ _brew_outdated() {
'--fetch-HEAD[detect if the HEAD installation of the formula is outdated]' \ '--fetch-HEAD[detect if the HEAD installation of the formula is outdated]' \
- cask \ - cask \
'--cask[list outdated Casks]' \ '--cask[list outdated Casks]' \
'--greedy[also list Casks with auto_updates or version \:latest]' \ '--greedy[also list Casks with auto_updates or version \:latest]'
} }
# brew pin formulae: # brew pin formulae:

View File

@ -364,9 +364,9 @@ If *`formula`* is provided, summarise the paths within its current keg.
* `--pinned`: * `--pinned`:
Show the versions of pinned formulae, or only the specified (pinned) formulae if *`formula`* are provided. See also `pin`, `unpin`. Show the versions of pinned formulae, or only the specified (pinned) formulae if *`formula`* are provided. See also `pin`, `unpin`.
* `--formula`: * `--formula`:
List only formulae. List only formulae. `This is the default action on non TTY.`
* `--cask`: * `--cask`:
List only casks. List only casks, or *`cask`* if provided.
* `-1`: * `-1`:
Force output to be one entry per line. This is the default when output is not to a terminal. Force output to be one entry per line. This is the default when output is not to a terminal.
* `-l`: * `-l`:

View File

@ -533,11 +533,11 @@ Show the versions of pinned formulae, or only the specified (pinned) formulae if
. .
.TP .TP
\fB\-\-formula\fR \fB\-\-formula\fR
List only formulae\. List only formulae\. \fBThis is the default action on non TTY\.\fR
. .
.TP .TP
\fB\-\-cask\fR \fB\-\-cask\fR
List only casks\. List only casks, or \fIcask\fR if provided\.
. .
.TP .TP
\fB\-1\fR \fB\-1\fR