list.rb: use CLI::Parser to better handle args
* --multiple now assumes --versions * Use CLI::Parser (that, in turns, uses OpenStruct) to handle arguments
This commit is contained in:
parent
67a1235487
commit
da66bf96b7
@ -20,13 +20,28 @@
|
|||||||
|
|
||||||
require "metafiles"
|
require "metafiles"
|
||||||
require "formula"
|
require "formula"
|
||||||
|
require "cli_parser"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def list
|
def list
|
||||||
|
@args = CLI::Parser.parse do
|
||||||
|
switch "--unbrewed"
|
||||||
|
switch "--pinned"
|
||||||
|
switch "--versions"
|
||||||
|
switch "--full-name"
|
||||||
|
switch "--multiple"
|
||||||
|
switch :verbose
|
||||||
|
end
|
||||||
|
|
||||||
|
if @args.multiple? && !@args.versions?
|
||||||
|
opoo "--multiple requires --versions"
|
||||||
|
@args.send("versions?=", true)
|
||||||
|
end
|
||||||
|
|
||||||
# Use of exec means we don't explicitly exit
|
# Use of exec means we don't explicitly exit
|
||||||
list_unbrewed if ARGV.flag? "--unbrewed"
|
list_unbrewed if @args.unbrewed?
|
||||||
|
|
||||||
# Unbrewed uses the PREFIX, which will exist
|
# Unbrewed uses the PREFIX, which will exist
|
||||||
# Things below use the CELLAR, which doesn't until the first formula is installed.
|
# Things below use the CELLAR, which doesn't until the first formula is installed.
|
||||||
@ -35,10 +50,10 @@ module Homebrew
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if ARGV.include?("--pinned") || ARGV.include?("--versions")
|
if @args.pinned? || @args.versions?
|
||||||
filtered_list
|
filtered_list
|
||||||
elsif ARGV.named.empty?
|
elsif ARGV.named.empty?
|
||||||
if ARGV.include? "--full-name"
|
if @args.full_name?
|
||||||
full_names = Formula.installed.map(&:full_name).sort(&tap_and_name_comparison)
|
full_names = Formula.installed.map(&:full_name).sort(&tap_and_name_comparison)
|
||||||
return if full_names.empty?
|
return if full_names.empty?
|
||||||
puts Formatter.columns(full_names)
|
puts Formatter.columns(full_names)
|
||||||
@ -46,7 +61,7 @@ module Homebrew
|
|||||||
ENV["CLICOLOR"] = nil
|
ENV["CLICOLOR"] = nil
|
||||||
exec "ls", *ARGV.options_only << HOMEBREW_CELLAR
|
exec "ls", *ARGV.options_only << HOMEBREW_CELLAR
|
||||||
end
|
end
|
||||||
elsif ARGV.verbose? || !$stdout.tty?
|
elsif Homebrew.args.verbose? || !$stdout.tty?
|
||||||
exec "find", *ARGV.kegs.map(&:to_s) + %w[-not -type d -print]
|
exec "find", *ARGV.kegs.map(&:to_s) + %w[-not -type d -print]
|
||||||
else
|
else
|
||||||
ARGV.kegs.each { |keg| PrettyListing.new keg }
|
ARGV.kegs.each { |keg| PrettyListing.new keg }
|
||||||
@ -87,13 +102,13 @@ module Homebrew
|
|||||||
dirs.delete "etc"
|
dirs.delete "etc"
|
||||||
dirs.delete "var"
|
dirs.delete "var"
|
||||||
|
|
||||||
args = dirs.sort + %w[-type f (]
|
arguments = dirs.sort + %w[-type f (]
|
||||||
args.concat UNBREWED_EXCLUDE_FILES.flat_map { |f| %W[! -name #{f}] }
|
arguments.concat UNBREWED_EXCLUDE_FILES.flat_map { |f| %W[! -name #{f}] }
|
||||||
args.concat UNBREWED_EXCLUDE_PATHS.flat_map { |d| %W[! -path #{d}] }
|
arguments.concat UNBREWED_EXCLUDE_PATHS.flat_map { |d| %W[! -path #{d}] }
|
||||||
args.concat %w[)]
|
arguments.concat %w[)]
|
||||||
|
|
||||||
cd HOMEBREW_PREFIX
|
cd HOMEBREW_PREFIX
|
||||||
exec "find", *args
|
exec "find", *arguments
|
||||||
end
|
end
|
||||||
|
|
||||||
def filtered_list
|
def filtered_list
|
||||||
@ -106,7 +121,7 @@ module Homebrew
|
|||||||
rack.exist?
|
rack.exist?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if ARGV.include? "--pinned"
|
if @args.pinned?
|
||||||
pinned_versions = {}
|
pinned_versions = {}
|
||||||
names.sort.each do |d|
|
names.sort.each do |d|
|
||||||
keg_pin = (HOMEBREW_PINNED_KEGS/d.basename.to_s)
|
keg_pin = (HOMEBREW_PINNED_KEGS/d.basename.to_s)
|
||||||
@ -115,12 +130,12 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
pinned_versions.each do |d, version|
|
pinned_versions.each do |d, version|
|
||||||
puts d.basename.to_s.concat(ARGV.include?("--versions") ? " #{version}" : "")
|
puts d.basename.to_s.concat(@args.versions? ? " #{version}" : "")
|
||||||
end
|
end
|
||||||
else # --versions without --pinned
|
else # --versions without --pinned
|
||||||
names.sort.each do |d|
|
names.sort.each do |d|
|
||||||
versions = d.subdirs.map { |pn| pn.basename.to_s }
|
versions = d.subdirs.map { |pn| pn.basename.to_s }
|
||||||
next if ARGV.include?("--multiple") && versions.length < 2
|
next if @args.multiple? && versions.length < 2
|
||||||
puts "#{d.basename} #{versions * " "}"
|
puts "#{d.basename} #{versions * " "}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user