From c8809ce730ed02f79c0efff4b76ba5e5207e5432 Mon Sep 17 00:00:00 2001 From: Akylzhan Sauranbay <akyl.sauranbai@gmail.com> Date: Mon, 5 Oct 2020 00:49:53 +0600 Subject: [PATCH] cmd/list.rb: --formula, --cask as default on TTY outputs cmd/list.rb: --formula, --cask as default TTY: cmd/list.rb: proper deprecated message on non TTY outputs update manpage update zsh completion updated manpages/brew.1 update tests return list_casks list_spec.rb: not output to stderr --- Library/Homebrew/cmd/list.rb | 12 +++++++++--- Library/Homebrew/test/cmd/list_spec.rb | 2 +- completions/zsh/_brew | 16 ++++++++++++---- docs/Manpage.md | 4 ++-- manpages/brew.1 | 4 ++-- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 3e55a88337..bfd03b0855 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -33,9 +33,9 @@ module Homebrew description: "Show the versions of pinned formulae, or only the specified (pinned) "\ "formulae if <formula> are provided. See also `pin`, `unpin`." switch "--formula", "--formulae", - description: "List only formulae." + description: "List only formulae. `This is the default action on non TTY.`" switch "--cask", "--casks", - description: "List only casks." + description: "List only casks, or <cask> if provided." # passed through to ls switch "-1", description: "Force output to be one entry per line. " \ @@ -86,7 +86,13 @@ module Homebrew ls_args << "-r" if args.r? 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 elsif args.verbose? || !$stdout.tty? system_command! "find", args: args.named.to_kegs.map(&:to_s) + %w[-not -type d -print], print_stdout: true diff --git a/Library/Homebrew/test/cmd/list_spec.rb b/Library/Homebrew/test/cmd/list_spec.rb index e12a8522d1..04a60e4adc 100644 --- a/Library/Homebrew/test/cmd/list_spec.rb +++ b/Library/Homebrew/test/cmd/list_spec.rb @@ -14,7 +14,7 @@ describe "brew list", :integration_test do (HOMEBREW_CELLAR/f/"1.0/somedir").mkpath end - expect { brew "list" } + expect { brew "list", "--formula" } .to output("#{formulae.join("\n")}\n").to_stdout .and not_to_output.to_stderr .and be_a_success diff --git a/completions/zsh/_brew b/completions/zsh/_brew index 140ecf5176..1ff67fac63 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -62,10 +62,17 @@ __brew_formulae() { __brew_installed_formulae() { local -a formulae - formulae=($(brew list)) + formulae=($(brew list --formula)) _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() { local -a formulae formulae=($(brew outdated)) @@ -493,11 +500,12 @@ _brew_linkage() { # brew list, ls [--full-name]: # brew list, ls --unbrewed: # brew list, ls [--versions [--multiple]] [--pinned] [formulae]: -# brew list, ls --cask: +# brew list, ls [--cask|--formula]: _brew_list() { local state _arguments \ - formulae \ + '--formula[list install formulae]' \ '--full-name[print formulae with fully-qualified names]' \ '--unbrewed[files in brew --prefix not controlled by brew]' \ '--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]' \ - cask \ '--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: @@ -818,7 +826,7 @@ _brew_update_test() { # install-options is copied from brew install _brew_upgrade() { _arguments \ - '--cask[upgrade installed Casks with newer versions]' + '--cask[upgrade installed Casks with newer versions]' \ '--cleanup[remove previously installed formula version(s)]' \ '--fetch-HEAD[detect if the HEAD installation of the formula is outdated]' \ - normal-install \ diff --git a/docs/Manpage.md b/docs/Manpage.md index 7d97dd8e20..3b3f557e55 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -424,9 +424,9 @@ If *`formula`* is provided, summarise the paths within its current keg. * `--pinned`: Show the versions of pinned formulae, or only the specified (pinned) formulae if *`formula`* are provided. See also `pin`, `unpin`. * `--formula`: - List only formulae. + List only formulae. `This is the default action on non TTY.` * `--cask`: - List only casks. + List only casks, or *`cask`* if provided. * `-1`: Force output to be one entry per line. This is the default when output is not to a terminal. * `-l`: diff --git a/manpages/brew.1 b/manpages/brew.1 index a13abf36f9..a81767a65e 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -653,11 +653,11 @@ Show the versions of pinned formulae, or only the specified (pinned) formulae if . .TP \fB\-\-formula\fR -List only formulae\. +List only formulae\. \fBThis is the default action on non TTY\.\fR . .TP \fB\-\-cask\fR -List only casks\. +List only casks, or \fIcask\fR if provided\. . .TP \fB\-1\fR -- GitLab