Class: Homebrew::Cmd::List

Inherits:
AbstractCommand show all
Includes:
SystemCommand::Mixin
Defined in:
cmd/list.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods included from SystemCommand::Mixin

#system_command, #system_command!

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'cmd/list.rb', line 69

def run
  if args.full_name?
    unless args.cask?
      formula_names = args.no_named? ? Formula.installed : args.named.to_resolved_formulae
      full_formula_names = formula_names.map(&:full_name).sort(&tap_and_name_comparison)
      full_formula_names = Formatter.columns(full_formula_names) unless args.public_send(:"1?")
      puts full_formula_names if full_formula_names.present?
    end
    if args.cask? || (!args.formula? && args.no_named?)
      cask_names = if args.no_named?
        Cask::Caskroom.casks
      else
        args.named.to_formulae_and_casks(only: :cask, method: :resolve)
      end
      # The cast is because `Keg`` does not define `full_name`
      full_cask_names = T.cast(cask_names, T::Array[T.any(Formula, Cask::Cask)])
                         .map(&:full_name).sort(&tap_and_name_comparison)
      full_cask_names = Formatter.columns(full_cask_names) unless args.public_send(:"1?")
      puts full_cask_names if full_cask_names.present?
    end
  elsif args.pinned?
    filtered_list
  elsif args.versions?
    filtered_list unless args.cask?
    list_casks if args.cask? || (!args.formula? && !args.multiple? && args.no_named?)
  elsif args.no_named?
    ENV["CLICOLOR"] = nil

    ls_args = []
    ls_args << "-1" if args.public_send(:"1?")
    ls_args << "-l" if args.l?
    ls_args << "-r" if args.r?
    ls_args << "-t" if args.t?

    if !args.cask? && HOMEBREW_CELLAR.exist? && HOMEBREW_CELLAR.children.any?
      ohai "Formulae" if $stdout.tty? && !args.formula?
      safe_system "ls", *ls_args, HOMEBREW_CELLAR
      puts if $stdout.tty? && !args.formula?
    end
    if !args.formula? && Cask::Caskroom.any_casks_installed?
      ohai "Casks" if $stdout.tty? && !args.cask?
      safe_system "ls", *ls_args, Cask::Caskroom.path
    end
  else
    kegs, casks = args.named.to_kegs_to_casks

    if args.verbose? || !$stdout.tty?
      find_args = %w[-not -type d -not -name .DS_Store -print]
      system_command! "find", args: kegs.map(&:to_s) + find_args, print_stdout: true if kegs.present?
      system_command! "find", args: casks.map(&:caskroom_path) + find_args, print_stdout: true if casks.present?
    else
      kegs.each { |keg| PrettyListing.new keg } if kegs.present?
      list_casks if casks.present?
    end
  end
end