Merge pull request #17125 from Homebrew/brew-list-manual-auto
cmd/list: support listing formulae installed on request or automatically
This commit is contained in:
		
						commit
						966454c97d
					
				@ -7,6 +7,7 @@ require "formula"
 | 
			
		||||
require "cli/parser"
 | 
			
		||||
require "cask/list"
 | 
			
		||||
require "system_command"
 | 
			
		||||
require "tab"
 | 
			
		||||
 | 
			
		||||
module Homebrew
 | 
			
		||||
  module Cmd
 | 
			
		||||
@ -36,6 +37,11 @@ module Homebrew
 | 
			
		||||
        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. " \
 | 
			
		||||
@ -54,11 +60,18 @@ module Homebrew
 | 
			
		||||
        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
 | 
			
		||||
 | 
			
		||||
@ -91,6 +104,28 @@ module Homebrew
 | 
			
		||||
        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)
 | 
			
		||||
 | 
			
		||||
            if args.installed_on_request? && args.installed_as_dependency?
 | 
			
		||||
              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(", ")}"
 | 
			
		||||
            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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -25,6 +25,12 @@ class Homebrew::Cmd::List::Args < Homebrew::CLI::Args
 | 
			
		||||
  sig { returns(T::Boolean) }
 | 
			
		||||
  def full_name?; end
 | 
			
		||||
 | 
			
		||||
  sig { returns(T::Boolean) }
 | 
			
		||||
  def installed_as_dependency?; end
 | 
			
		||||
 | 
			
		||||
  sig { returns(T::Boolean) }
 | 
			
		||||
  def installed_on_request?; end
 | 
			
		||||
 | 
			
		||||
  sig { returns(T::Boolean) }
 | 
			
		||||
  def l?; end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -19,8 +19,10 @@ RSpec.describe Tapioca::Compilers::Args do
 | 
			
		||||
  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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1422,6 +1422,8 @@ _brew_list() {
 | 
			
		||||
      --formula
 | 
			
		||||
      --full-name
 | 
			
		||||
      --help
 | 
			
		||||
      --installed-as-dependency
 | 
			
		||||
      --installed-on-request
 | 
			
		||||
      --multiple
 | 
			
		||||
      --pinned
 | 
			
		||||
      --quiet
 | 
			
		||||
@ -1524,6 +1526,8 @@ _brew_ls() {
 | 
			
		||||
      --formula
 | 
			
		||||
      --full-name
 | 
			
		||||
      --help
 | 
			
		||||
      --installed-as-dependency
 | 
			
		||||
      --installed-on-request
 | 
			
		||||
      --multiple
 | 
			
		||||
      --pinned
 | 
			
		||||
      --quiet
 | 
			
		||||
 | 
			
		||||
@ -997,6 +997,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'
 | 
			
		||||
@ -1063,6 +1065,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'
 | 
			
		||||
 | 
			
		||||
@ -1234,13 +1234,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]' \
 | 
			
		||||
@ -1249,7 +1251,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'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1315,13 +1317,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]' \
 | 
			
		||||
@ -1330,7 +1334,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'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -749,6 +749,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
 | 
			
		||||
 | 
			
		||||
@ -470,6 +470,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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user