cmd: use more and cleanup new args APIs.

This commit is contained in:
Mike McQuaid 2020-03-04 17:28:15 +00:00
parent ad32d387e9
commit a7fe0ed847
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
41 changed files with 126 additions and 146 deletions

View File

@ -26,10 +26,10 @@ module Homebrew
def __cache def __cache
__cache_args.parse __cache_args.parse
if ARGV.named.empty? if args.no_named?
puts HOMEBREW_CACHE puts HOMEBREW_CACHE
else else
Homebrew.args.formulae.each do |f| args.formulae.each do |f|
if Fetch.fetch_bottle?(f) if Fetch.fetch_bottle?(f)
puts f.bottle.cached_download puts f.bottle.cached_download
else else

View File

@ -22,10 +22,10 @@ module Homebrew
def __cellar def __cellar
__cellar_args.parse __cellar_args.parse
if Homebrew.args.named.blank? if args.no_named?
puts HOMEBREW_CELLAR puts HOMEBREW_CELLAR
else else
puts Homebrew.args.resolved_formulae.map(&:rack) puts args.resolved_formulae.map(&:rack)
end end
end end
end end

View File

@ -30,9 +30,8 @@ module Homebrew
__env_args.parse __env_args.parse
ENV.activate_extensions! ENV.activate_extensions!
ENV.deps = Homebrew.args.formulae if superenv? ENV.deps = args.formulae if superenv?
ENV.setup_build_environment ENV.setup_build_environment
ENV.universal_binary if ARGV.build_universal?
shell = if args.plain? shell = if args.plain?
nil nil

View File

@ -22,10 +22,10 @@ module Homebrew
def __prefix def __prefix
__prefix_args.parse __prefix_args.parse
if Homebrew.args.named.blank? if args.no_named?
puts HOMEBREW_PREFIX puts HOMEBREW_PREFIX
else else
puts Homebrew.args.resolved_formulae.map { |f| puts args.resolved_formulae.map { |f|
f.opt_prefix.exist? ? f.opt_prefix : f.installed_prefix f.opt_prefix.exist? ? f.opt_prefix : f.installed_prefix
} }
end end

View File

@ -20,10 +20,10 @@ module Homebrew
def __repository def __repository
__repository_args.parse __repository_args.parse
if ARGV.named.empty? if args.no_named?
puts HOMEBREW_REPOSITORY puts HOMEBREW_REPOSITORY
else else
puts ARGV.named.map { |tap| Tap.fetch(tap).path } puts args.named.map { |tap| Tap.fetch(tap).path }
end end
end end
end end

View File

@ -26,7 +26,7 @@ module Homebrew
def analytics def analytics
analytics_args.parse analytics_args.parse
case args.remaining.first case args.named.first
when nil, "state" when nil, "state"
if Utils::Analytics.disabled? if Utils::Analytics.disabled?
puts "Analytics are disabled." puts "Analytics are disabled."
@ -41,7 +41,7 @@ module Homebrew
when "regenerate-uuid" when "regenerate-uuid"
Utils::Analytics.regenerate_uuid! Utils::Analytics.regenerate_uuid!
else else
raise UsageError, "Unknown subcommand." raise UsageError, "unknown subcommand"
end end
end end
end end

View File

@ -12,17 +12,12 @@ module Homebrew
Display the source of <formula>. Display the source of <formula>.
EOS EOS
max_named 1 named :formula
end end
end end
def cat def cat
cat_args.parse cat_args.parse
# do not "fix" this to support multiple arguments, the output would be
# unparsable; if the user wants to cat multiple formula they can call
# `brew cat` multiple times.
formulae = Homebrew.args.formulae
raise FormulaUnspecifiedError if formulae.empty?
cd HOMEBREW_REPOSITORY cd HOMEBREW_REPOSITORY
pager = if ENV["HOMEBREW_BAT"].nil? pager = if ENV["HOMEBREW_BAT"].nil?
@ -30,6 +25,6 @@ module Homebrew
else else
"#{HOMEBREW_PREFIX}/bin/bat" "#{HOMEBREW_PREFIX}/bin/bat"
end end
safe_system pager, formulae.first.path, *Homebrew.args.passthrough safe_system pager, args.formulae.first.path, *args.passthrough
end end
end end

View File

@ -33,7 +33,7 @@ module Homebrew
def cleanup def cleanup
cleanup_args.parse cleanup_args.parse
cleanup = Cleanup.new(*args.remaining, dry_run: args.dry_run?, scrub: args.s?, days: args.prune&.to_i) cleanup = Cleanup.new(*args.named, dry_run: args.dry_run?, scrub: args.s?, days: args.prune&.to_i)
if args.prune_prefix? if args.prune_prefix?
cleanup.prune_prefix_symlinks_and_directories cleanup.prune_prefix_symlinks_and_directories
return return

View File

@ -15,15 +15,14 @@ module Homebrew
EOS EOS
switch :verbose switch :verbose
switch :debug switch :debug
min_named 1
end end
end end
def command def command
command_args.parse command_args.parse
raise UsageError, "This command requires a command argument" if args.remaining.empty? args.named.each do |cmd|
args.remaining.each do |cmd|
path = Commands.path(cmd) path = Commands.path(cmd)
odie "Unknown command: #{cmd}" unless path odie "Unknown command: #{cmd}" unless path
puts path puts path

View File

@ -62,7 +62,7 @@ module Homebrew
Formulary.enable_factory_cache! Formulary.enable_factory_cache!
recursive = !args.send("1?") recursive = !args.send("1?")
installed = args.installed? || ARGV.formulae.all?(&:opt_or_installed_prefix_keg) installed = args.installed? || args.formulae.all?(&:opt_or_installed_prefix_keg)
@use_runtime_dependencies = installed && recursive && @use_runtime_dependencies = installed && recursive &&
!args.include_build? && !args.include_build? &&
@ -74,27 +74,27 @@ module Homebrew
if args.installed? if args.installed?
puts_deps_tree Formula.installed.sort, recursive puts_deps_tree Formula.installed.sort, recursive
else else
raise FormulaUnspecifiedError if Homebrew.args.remaining.empty? raise FormulaUnspecifiedError if args.no_named?
puts_deps_tree Homebrew.args.formulae, recursive puts_deps_tree args.formulae, recursive
end end
return return
elsif args.all? elsif args.all?
puts_deps Formula.sort, recursive puts_deps Formula.sort, recursive
return return
elsif !Homebrew.args.remaining.empty? && args.for_each? elsif !args.no_named? && args.for_each?
puts_deps Homebrew.args.formulae, recursive puts_deps args.formulae, recursive
return return
end end
if Homebrew.args.remaining.empty? if args.no_named?
raise FormulaUnspecifiedError unless args.installed? raise FormulaUnspecifiedError unless args.installed?
puts_deps Formula.installed.sort, recursive puts_deps Formula.installed.sort, recursive
return return
end end
all_deps = deps_for_formulae(Homebrew.args.formulae, recursive, &(args.union? ? :| : :&)) all_deps = deps_for_formulae(args.formulae, recursive, &(args.union? ? :| : :&))
all_deps = condense_requirements(all_deps) all_deps = condense_requirements(all_deps)
all_deps.select!(&:installed?) if args.installed? all_deps.select!(&:installed?) if args.installed?
all_deps.map!(&method(:dep_display_name)) all_deps.map!(&method(:dep_display_name))

View File

@ -40,16 +40,16 @@ module Homebrew
search_type << :either if args.search search_type << :either if args.search
search_type << :name if args.name search_type << :name if args.name
search_type << :desc if args.description search_type << :desc if args.description
odie "You must provide a search term." if search_type.present? && ARGV.named.empty? odie "You must provide a search term." if search_type.present? && args.no_named?
results = if search_type.empty? results = if search_type.empty?
raise FormulaUnspecifiedError if ARGV.named.empty? raise FormulaUnspecifiedError if args.no_named?
desc = {} desc = {}
Homebrew.args.formulae.each { |f| desc[f.full_name] = f.desc } args.formulae.each { |f| desc[f.full_name] = f.desc }
Descriptions.new(desc) Descriptions.new(desc)
else else
arg = ARGV.named.join(" ") arg = args.named.join(" ")
string_or_regex = query_regexp(arg) string_or_regex = query_regexp(arg)
CacheStoreDatabase.use(:descriptions) do |db| CacheStoreDatabase.use(:descriptions) do |db|
cache_store = DescriptionCacheStore.new(db) cache_store = DescriptionCacheStore.new(db)

View File

@ -39,14 +39,14 @@ module Homebrew
exit exit
end end
if ARGV.named.empty? if args.no_named?
slow_checks = %w[ slow_checks = %w[
check_for_broken_symlinks check_for_broken_symlinks
check_missing_deps check_missing_deps
] ]
methods = (checks.all.sort - slow_checks) + slow_checks methods = (checks.all.sort - slow_checks) + slow_checks
else else
methods = ARGV.named methods = args.named
end end
first_warning = true first_warning = true

View File

@ -39,23 +39,22 @@ module Homebrew
switch :debug switch :debug
conflicts "--devel", "--HEAD" conflicts "--devel", "--HEAD"
conflicts "--build-from-source", "--build-bottle", "--force-bottle" conflicts "--build-from-source", "--build-bottle", "--force-bottle"
min_named :formula
end end
end end
def fetch def fetch
fetch_args.parse fetch_args.parse
raise FormulaUnspecifiedError if ARGV.named.empty?
if args.deps? if args.deps?
bucket = [] bucket = []
Homebrew.args.formulae.each do |f| args.formulae.each do |f|
bucket << f bucket << f
bucket.concat f.recursive_dependencies.map(&:to_formula) bucket.concat f.recursive_dependencies.map(&:to_formula)
end end
bucket.uniq! bucket.uniq!
else else
bucket = Homebrew.args.formulae bucket = args.formulae
end end
puts "Fetching: #{bucket * ", "}" if bucket.size > 1 puts "Fetching: #{bucket * ", "}" if bucket.size > 1

View File

@ -142,10 +142,10 @@ module Homebrew
def gist_logs def gist_logs
gist_logs_args.parse gist_logs_args.parse
raise FormulaUnspecifiedError if Homebrew.args.resolved_formulae.length != 1 raise FormulaUnspecifiedError if args.resolved_formulae.length != 1
Install.perform_preinstall_checks(all_fatal: true) Install.perform_preinstall_checks(all_fatal: true)
Install.perform_build_from_source_checks(all_fatal: true) Install.perform_build_from_source_checks(all_fatal: true)
gistify_logs(Homebrew.args.resolved_formulae.first) gistify_logs(args.resolved_formulae.first)
end end
end end

View File

@ -20,10 +20,10 @@ module Homebrew
def home def home
home_args.parse home_args.parse
if args.remaining.empty? if args.no_named?
exec_browser HOMEBREW_WWW exec_browser HOMEBREW_WWW
else else
exec_browser(*Homebrew.args.formulae.map(&:homepage)) exec_browser(*args.formulae.map(&:homepage))
end end
end end
end end

View File

@ -67,7 +67,7 @@ module Homebrew
end end
if args.category.present? if args.category.present?
if Homebrew.args.named.present? && !VALID_FORMULA_CATEGORIES.include?(args.category) if args.named.present? && !VALID_FORMULA_CATEGORIES.include?(args.category)
raise UsageError, "--category must be one of #{VALID_FORMULA_CATEGORIES.join(", ")} when querying formulae" raise UsageError, "--category must be one of #{VALID_FORMULA_CATEGORIES.join(", ")} when querying formulae"
end end
@ -77,23 +77,24 @@ module Homebrew
end end
if args.json if args.json
raise UsageError, "Invalid JSON version: #{args.json}" unless ["v1", true].include? args.json raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
if !(args.all? || args.installed?) && Homebrew.args.named.blank?
raise UsageError, "This command's option requires a formula argument" if !(args.all? || args.installed?) && args.no_named?
raise FormulaUnspecifiedError if args.no_named?
end end
print_json print_json
elsif args.github? elsif args.github?
raise UsageError, "This command's option requires a formula argument" if Homebrew.args.named.blank? raise FormulaUnspecifiedError if args.no_named?
exec_browser(*Homebrew.args.formulae.map { |f| github_info(f) }) exec_browser(*args.formulae.map { |f| github_info(f) })
else else
print_info print_info
end end
end end
def print_info def print_info
if Homebrew.args.named.blank? if args.no_named?
if args.analytics? if args.analytics?
Utils::Analytics.output Utils::Analytics.output
elsif HOMEBREW_CELLAR.exist? elsif HOMEBREW_CELLAR.exist?
@ -101,7 +102,7 @@ module Homebrew
puts "#{count} #{"keg".pluralize(count)}, #{HOMEBREW_CELLAR.dup.abv}" puts "#{count} #{"keg".pluralize(count)}, #{HOMEBREW_CELLAR.dup.abv}"
end end
else else
Homebrew.args.named.each_with_index do |f, i| args.named.each_with_index do |f, i|
puts unless i.zero? puts unless i.zero?
begin begin
formula = if f.include?("/") || File.exist?(f) formula = if f.include?("/") || File.exist?(f)
@ -135,7 +136,7 @@ module Homebrew
elsif args.installed? elsif args.installed?
Formula.installed.sort Formula.installed.sort
else else
Homebrew.args.formulae args.formulae
end end
json = ff.map(&:to_hash) json = ff.map(&:to_hash)
puts JSON.generate(json) puts JSON.generate(json)

View File

@ -88,13 +88,14 @@ module Homebrew
conflicts "--devel", "--HEAD" conflicts "--devel", "--HEAD"
conflicts "--build-from-source", "--build-bottle", "--force-bottle" conflicts "--build-from-source", "--build-bottle", "--force-bottle"
formula_options formula_options
min_named :formula
end end
end end
def install def install
install_args.parse install_args.parse
Homebrew.args.named.each do |name| args.named.each do |name|
next if File.exist?(name) next if File.exist?(name)
next if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_CASK_REGEX next if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_CASK_REGEX
@ -102,8 +103,6 @@ module Homebrew
tap.install unless tap.installed? tap.install unless tap.installed?
end end
raise FormulaUnspecifiedError if args.remaining.empty?
if args.ignore_dependencies? if args.ignore_dependencies?
opoo <<~EOS opoo <<~EOS
#{Tty.bold}--ignore-dependencies is an unsupported Homebrew developer flag!#{Tty.reset} #{Tty.bold}--ignore-dependencies is an unsupported Homebrew developer flag!#{Tty.reset}
@ -131,9 +130,9 @@ module Homebrew
# developer tools are available, we need to stop them early on # developer tools are available, we need to stop them early on
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
Homebrew.args.formulae.each do |f| args.formulae.each do |f|
# head-only without --HEAD is an error # head-only without --HEAD is an error
if !Homebrew.args.HEAD? && f.stable.nil? && f.devel.nil? if !args.HEAD? && f.stable.nil? && f.devel.nil?
raise <<~EOS raise <<~EOS
#{f.full_name} is a head-only formula #{f.full_name} is a head-only formula
Install with `brew install --HEAD #{f.full_name}` Install with `brew install --HEAD #{f.full_name}`

View File

@ -25,20 +25,19 @@ module Homebrew
description: "Allow keg-only formulae to be linked." description: "Allow keg-only formulae to be linked."
switch :verbose switch :verbose
switch :debug switch :debug
min_named :keg
end end
end end
def link def link
link_args.parse link_args.parse
raise KegUnspecifiedError if ARGV.named.empty?
mode = OpenStruct.new mode = OpenStruct.new
mode.overwrite = true if args.overwrite? mode.overwrite = true if args.overwrite?
mode.dry_run = true if args.dry_run? mode.dry_run = true if args.dry_run?
Homebrew.args.kegs.each do |keg| args.kegs.each do |keg|
keg_only = Formulary.keg_only?(keg.rack) keg_only = Formulary.keg_only?(keg.rack)
if keg.linked? if keg.linked?

View File

@ -55,14 +55,14 @@ module Homebrew
# 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.
unless HOMEBREW_CELLAR.exist? unless HOMEBREW_CELLAR.exist?
raise NoSuchKegError, Hombrew.args.named.first if Homebrew.args.named.present? raise NoSuchKegError, Hombrew.args.named.first if args.named.present?
return return
end end
if args.pinned? || args.versions? if args.pinned? || args.versions?
filtered_list filtered_list
elsif Homebrew.args.named.blank? elsif args.no_named?
if args.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?
@ -70,12 +70,12 @@ module Homebrew
puts Formatter.columns(full_names) puts Formatter.columns(full_names)
else else
ENV["CLICOLOR"] = nil ENV["CLICOLOR"] = nil
safe_system "ls", *Homebrew.args.passthrough << HOMEBREW_CELLAR safe_system "ls", *args.passthrough << HOMEBREW_CELLAR
end end
elsif args.verbose? || !$stdout.tty? elsif args.verbose? || !$stdout.tty?
system_command! "find", args: Homebrew.args.kegs.map(&:to_s) + %w[-not -type d -print], print_stdout: true system_command! "find", args: args.kegs.map(&:to_s) + %w[-not -type d -print], print_stdout: true
else else
Homebrew.args.kegs.each { |keg| PrettyListing.new keg } args.kegs.each { |keg| PrettyListing.new keg }
end end
end end
@ -123,10 +123,10 @@ module Homebrew
end end
def filtered_list def filtered_list
names = if Homebrew.args.named.blank? names = if args.no_named?
Formula.racks Formula.racks
else else
racks = Homebrew.args.named.map { |n| Formulary.to_rack(n) } racks = args.named.map { |n| Formulary.to_rack(n) }
racks.select do |rack| racks.select do |rack|
Homebrew.failed = true unless rack.exist? Homebrew.failed = true unless rack.exist?
rack.exist? rack.exist?

View File

@ -33,10 +33,10 @@ module Homebrew
# user path, too. # user path, too.
ENV["PATH"] = ENV["HOMEBREW_PATH"] ENV["PATH"] = ENV["HOMEBREW_PATH"]
if ARGV.named.empty? if args.no_named?
git_log HOMEBREW_REPOSITORY git_log HOMEBREW_REPOSITORY
else else
path = Formulary.path(ARGV.named.first) path = Formulary.path(args.named.first)
tap = Tap.from_path(path) tap = Tap.from_path(path)
git_log path.dirname, path, tap git_log path.dirname, path, tap
end end
@ -62,8 +62,8 @@ module Homebrew
git -C "#{git_cd}" fetch --unshallow git -C "#{git_cd}" fetch --unshallow
EOS EOS
end end
args = Homebrew.args.options_only system_args = args.options_only
args += ["--follow", "--", path] unless path.nil? system_args += ["--follow", "--", path] if path.present?
system "git", "log", *args system "git", "log", *system_args
end end
end end

View File

@ -19,15 +19,14 @@ module Homebrew
"the same taps and migrate them anyway." "the same taps and migrate them anyway."
switch :verbose switch :verbose
switch :debug switch :debug
min_named :formula
end end
end end
def migrate def migrate
migrate_args.parse migrate_args.parse
raise FormulaUnspecifiedError if Homebrew.args.named.blank? args.resolved_formulae.each do |f|
Homebrew.args.resolved_formulae.each do |f|
if f.oldname if f.oldname
unless (rack = HOMEBREW_CELLAR/f.oldname).exist? && !rack.subdirs.empty? unless (rack = HOMEBREW_CELLAR/f.oldname).exist? && !rack.subdirs.empty?
raise NoSuchKegError, f.oldname raise NoSuchKegError, f.oldname

View File

@ -30,10 +30,10 @@ module Homebrew
return unless HOMEBREW_CELLAR.exist? return unless HOMEBREW_CELLAR.exist?
ff = if Homebrew.args.named.blank? ff = if args.no_named?
Formula.installed.sort Formula.installed.sort
else else
Homebrew.args.resolved_formulae.sort args.resolved_formulae.sort
end end
ff.each do |f| ff.each do |f|

View File

@ -32,10 +32,10 @@ module Homebrew
puts_options Formula.to_a.sort puts_options Formula.to_a.sort
elsif args.installed? elsif args.installed?
puts_options Formula.installed.sort puts_options Formula.installed.sort
elsif args.no_named?
raise FormulaUnspecifiedError
else else
raise FormulaUnspecifiedError if args.remaining.empty? puts_options args.formulae
puts_options Homebrew.args.formulae
end end
end end

View File

@ -35,19 +35,19 @@ module Homebrew
def outdated def outdated
outdated_args.parse outdated_args.parse
formulae = if Homebrew.args.resolved_formulae.blank? formulae = if args.resolved_formulae.blank?
Formula.installed Formula.installed
else else
Homebrew.args.resolved_formulae args.resolved_formulae
end end
if args.json if args.json
raise UsageError, "Invalid JSON version: #{args.json}" unless ["v1", true].include? args.json raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
outdated = print_outdated_json(formulae) outdated = print_outdated_json(formulae)
else else
outdated = print_outdated(formulae) outdated = print_outdated(formulae)
end end
Homebrew.failed = Homebrew.args.resolved_formulae.present? && !outdated.empty? Homebrew.failed = args.resolved_formulae.present? && !outdated.empty?
end end
def print_outdated(formulae) def print_outdated(formulae)

View File

@ -15,15 +15,14 @@ module Homebrew
issuing the `brew upgrade` <formula> command. See also `unpin`. issuing the `brew upgrade` <formula> command. See also `unpin`.
EOS EOS
switch :debug switch :debug
min_named :formula
end end
end end
def pin def pin
pin_args.parse pin_args.parse
raise FormulaUnspecifiedError if args.remaining.empty? args.resolved_formulae.each do |f|
Homebrew.args.resolved_formulae.each do |f|
if f.pinned? if f.pinned?
opoo "#{f.name} already pinned" opoo "#{f.name} already pinned"
elsif !f.pinnable? elsif !f.pinnable?

View File

@ -17,15 +17,14 @@ module Homebrew
switch :force switch :force
switch :verbose switch :verbose
switch :debug switch :debug
min_named :keg
end end
end end
def postinstall def postinstall
postinstall_args.parse postinstall_args.parse
raise KegUnspecifiedError if args.remaining.empty? args.resolved_formulae.each do |f|
Homebrew.args.resolved_formulae.each do |f|
ohai "Postinstalling #{f}" ohai "Postinstalling #{f}"
fi = FormulaInstaller.new(f) fi = FormulaInstaller.new(f)
fi.post_install fi.post_install

View File

@ -36,10 +36,10 @@ module Homebrew
end end
options = { aliases: args.aliases? } options = { aliases: args.aliases? }
taps = if ARGV.named.empty? taps = if args.no_named?
Tap Tap
else else
ARGV.named.map { |t| Tap.fetch(t) } args.named.map { |t| Tap.fetch(t) }
end end
taps.each do |tap| taps.each do |tap|
Homebrew.failed = true unless Readall.valid_tap?(tap, options) Homebrew.failed = true unless Readall.valid_tap?(tap, options)

View File

@ -45,19 +45,18 @@ module Homebrew
description: "Print install times for each formula at the end of the run." description: "Print install times for each formula at the end of the run."
conflicts "--build-from-source", "--force-bottle" conflicts "--build-from-source", "--force-bottle"
formula_options formula_options
min_named :formula
end end
end end
def reinstall def reinstall
reinstall_args.parse reinstall_args.parse
raise FormulaUnspecifiedError if args.remaining.empty?
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
Install.perform_preinstall_checks Install.perform_preinstall_checks
Homebrew.args.resolved_formulae.each do |f| args.resolved_formulae.each do |f|
if f.pinned? if f.pinned?
onoe "#{f.full_name} is pinned. You must unpin it to reinstall." onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
next next

View File

@ -62,13 +62,13 @@ module Homebrew
if package_manager = PACKAGE_MANAGERS.find { |name,| args[:"#{name}?"] } if package_manager = PACKAGE_MANAGERS.find { |name,| args[:"#{name}?"] }
_, url = package_manager _, url = package_manager
exec_browser url.call(URI.encode_www_form_component(args.remaining.join(" "))) exec_browser url.call(URI.encode_www_form_component(args.named.join(" ")))
return return
end end
if args.remaining.empty? if args.no_named?
if args.casks? if args.casks?
raise UsageError, "specifying both --formulae and --casks requires an argument!" if args.formulae? raise UsageError, "specifying both --formulae and --casks requires <text>" if args.formulae?
puts Formatter.columns(Cask::Cask.to_a.map(&:full_name).sort) puts Formatter.columns(Cask::Cask.to_a.map(&:full_name).sort)
else else
@ -78,7 +78,7 @@ module Homebrew
return return
end end
query = args.remaining.join(" ") query = args.named.join(" ")
string_or_regex = query_regexp(query) string_or_regex = query_regexp(query)
if args.desc? if args.desc?
@ -125,11 +125,11 @@ module Homebrew
end end
return unless $stdout.tty? return unless $stdout.tty?
return if args.remaining.empty? return if args.no_named?
metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ?].freeze metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ?].freeze
return unless metacharacters.any? do |char| return unless metacharacters.any? do |char|
args.remaining.any? do |arg| args.named.any? do |arg|
arg.include?(char) && !arg.start_with?("/") arg.include?(char) && !arg.start_with?("/")
end end
end end

View File

@ -38,14 +38,14 @@ module Homebrew
def style def style
style_args.parse style_args.parse
target = if Homebrew.args.named.blank? target = if args.no_named?
nil nil
elsif Homebrew.args.named.any? { |file| File.exist? file } elsif args.named.any? { |file| File.exist? file }
Homebrew.args.named args.named
elsif Homebrew.args.named.any? { |tap| tap.count("/") == 1 } elsif args.named.any? { |tap| tap.count("/") == 1 }
Homebrew.args.named.map { |tap| Tap.fetch(tap).path } args.named.map { |tap| Tap.fetch(tap).path }
else else
Homebrew.args.formulae.map(&:path) args.formulae.map(&:path)
end end
only_cops = args.only_cops only_cops = args.only_cops

View File

@ -16,16 +16,14 @@ module Homebrew
EOS EOS
switch :verbose switch :verbose
switch :debug switch :debug
max_named 2 named 2
end end
end end
def switch def switch
switch_args.parse switch_args.parse
raise FormulaUnspecifiedError if args.remaining.empty? name = args.named.first
name = args.remaining.first
rack = Formulary.to_rack(name) rack = Formulary.to_rack(name)
odie "#{name} not found in the Cellar." unless rack.directory? odie "#{name} not found in the Cellar." unless rack.directory?
@ -34,8 +32,7 @@ module Homebrew
.map { |d| Keg.new(d).version } .map { |d| Keg.new(d).version }
.sort .sort
.join(", ") .join(", ")
version = args.remaining.second version = args.named.second
raise UsageError, "Specify one of #{name}'s installed versions: #{versions}" unless version
odie <<~EOS unless (rack/version).directory? odie <<~EOS unless (rack/version).directory?
#{name} does not have a version \"#{version}\" in the Cellar. #{name} does not have a version \"#{version}\" in the Cellar.

View File

@ -30,13 +30,13 @@ module Homebrew
if args.installed? if args.installed?
taps = Tap taps = Tap
else else
taps = Homebrew.args.named.sort.map do |name| taps = args.named.sort.map do |name|
Tap.fetch(name) Tap.fetch(name)
end end
end end
if args.json if args.json
raise UsageError, "Invalid JSON version: #{args.json}" unless ["v1", true].include? args.json raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
print_tap_json(taps.sort_by(&:to_s)) print_tap_json(taps.sort_by(&:to_s))
else else

View File

@ -48,14 +48,14 @@ module Homebrew
Tap.each(&:link_completions_and_manpages) Tap.each(&:link_completions_and_manpages)
elsif args.list_pinned? elsif args.list_pinned?
puts Tap.select(&:pinned?).map(&:name) puts Tap.select(&:pinned?).map(&:name)
elsif ARGV.named.empty? elsif args.no_named?
puts Tap.names puts Tap.names
else else
tap = Tap.fetch(ARGV.named.first) tap = Tap.fetch(args.named.first)
begin begin
tap.install clone_target: ARGV.named.second, tap.install clone_target: args.named.second,
force_auto_update: force_auto_update?, force_auto_update: force_auto_update?,
quiet: Homebrew.args.quiet? quiet: args.quiet?
rescue TapRemoteMismatchError => e rescue TapRemoteMismatchError => e
odie e odie e
rescue TapAlreadyTappedError rescue TapAlreadyTappedError

View File

@ -22,23 +22,22 @@ module Homebrew
description: "Don't fail uninstall, even if <formula> is a dependency of any installed "\ description: "Don't fail uninstall, even if <formula> is a dependency of any installed "\
"formulae." "formulae."
switch :debug switch :debug
min_named :formula
end end
end end
def uninstall def uninstall
uninstall_args.parse uninstall_args.parse
raise KegUnspecifiedError if args.remaining.empty?
kegs_by_rack = if args.force? kegs_by_rack = if args.force?
Hash[ARGV.named.map do |name| Hash[args.named.map do |name|
rack = Formulary.to_rack(name) rack = Formulary.to_rack(name)
next unless rack.directory? next unless rack.directory?
[rack, rack.subdirs.map { |d| Keg.new(d) }] [rack, rack.subdirs.map { |d| Keg.new(d) }]
end] end]
else else
Homebrew.args.kegs.group_by(&:rack) args.kegs.group_by(&:rack)
end end
handle_unsatisfied_dependents(kegs_by_rack) handle_unsatisfied_dependents(kegs_by_rack)
@ -131,7 +130,7 @@ module Homebrew
protected protected
def sample_command def sample_command
"brew uninstall --ignore-dependencies #{ARGV.named.join(" ")}" "brew uninstall --ignore-dependencies #{Homebrew.args.named.join(" ")}"
end end
def are_required_by_deps def are_required_by_deps

View File

@ -20,18 +20,17 @@ module Homebrew
"deleting any files." "deleting any files."
switch :verbose switch :verbose
switch :debug switch :debug
min_named :keg
end end
end end
def unlink def unlink
unlink_args.parse unlink_args.parse
raise KegUnspecifiedError if args.remaining.empty?
mode = OpenStruct.new mode = OpenStruct.new
mode.dry_run = true if args.dry_run? mode.dry_run = true if args.dry_run?
Homebrew.args.kegs.each do |keg| args.kegs.each do |keg|
if mode.dry_run if mode.dry_run
puts "Would remove:" puts "Would remove:"
keg.unlink(mode) keg.unlink(mode)

View File

@ -32,7 +32,7 @@ module Homebrew
def unpack def unpack
unpack_args.parse unpack_args.parse
formulae = Homebrew.args.formulae formulae = args.formulae
raise FormulaUnspecifiedError if formulae.empty? raise FormulaUnspecifiedError if formulae.empty?
if dir = args.destdir if dir = args.destdir

View File

@ -22,9 +22,9 @@ module Homebrew
def unpin def unpin
unpin_args.parse unpin_args.parse
raise FormulaUnspecifiedError if args.remaining.empty? raise FormulaUnspecifiedError if args.no_named?
Homebrew.args.resolved_formulae.each do |f| args.resolved_formulae.each do |f|
if f.pinned? if f.pinned?
f.unpin f.unpin
elsif !f.pinnable? elsif !f.pinnable?

View File

@ -13,15 +13,14 @@ module Homebrew
Remove a tapped formula repository. Remove a tapped formula repository.
EOS EOS
switch :debug switch :debug
min_named 1
end end
end end
def untap def untap
untap_args.parse untap_args.parse
raise UsageError, "This command requires a tap argument from `brew tap`'s list" if args.remaining.empty? args.named.each do |tapname|
ARGV.named.each do |tapname|
tap = Tap.fetch(tapname) tap = Tap.fetch(tapname)
odie "Untapping #{tap} is not allowed" if tap.core_tap? odie "Untapping #{tap} is not allowed" if tap.core_tap?

View File

@ -13,7 +13,7 @@ module Homebrew
def update_preinstall_header def update_preinstall_header
@update_preinstall_header ||= begin @update_preinstall_header ||= begin
ohai "Auto-updated Homebrew!" if ARGV.include?("--preinstall") ohai "Auto-updated Homebrew!" if args.preinstall?
true true
end end
end end
@ -109,7 +109,7 @@ module Homebrew
end end
if !updated if !updated
puts "Already up-to-date." if !ARGV.include?("--preinstall") && !ENV["HOMEBREW_UPDATE_FAILED"] puts "Already up-to-date." if !args.preinstall? && !ENV["HOMEBREW_UPDATE_FAILED"]
else else
if hub.empty? if hub.empty?
puts "No changes to formulae." puts "No changes to formulae."
@ -122,7 +122,7 @@ module Homebrew
.update_from_report!(hub) .update_from_report!(hub)
end end
end end
puts if ARGV.include?("--preinstall") puts if args.preinstall?
end end
link_completions_manpages_and_docs link_completions_manpages_and_docs

View File

@ -65,18 +65,18 @@ module Homebrew
Install.perform_preinstall_checks Install.perform_preinstall_checks
if Homebrew.args.named.blank? if args.no_named?
outdated = Formula.installed.select do |f| outdated = Formula.installed.select do |f|
f.outdated?(fetch_head: args.fetch_HEAD?) f.outdated?(fetch_head: args.fetch_HEAD?)
end end
exit 0 if outdated.empty? exit 0 if outdated.empty?
else else
outdated = Homebrew.args.resolved_formulae.select do |f| outdated = args.resolved_formulae.select do |f|
f.outdated?(fetch_head: args.fetch_HEAD?) f.outdated?(fetch_head: args.fetch_HEAD?)
end end
(Homebrew.args.resolved_formulae - outdated).each do |f| (args.resolved_formulae - outdated).each do |f|
versions = f.installed_kegs.map(&:version) versions = f.installed_kegs.map(&:version)
if versions.empty? if versions.empty?
ofail "#{f.full_specified_name} not installed" ofail "#{f.full_specified_name} not installed"
@ -168,7 +168,7 @@ module Homebrew
tab = Tab.for_keg(keg) tab = Tab.for_keg(keg)
end end
build_options = BuildOptions.new(Options.create(Homebrew.args.flags_only), f.options) build_options = BuildOptions.new(Options.create(args.flags_only), f.options)
options = build_options.used_options options = build_options.used_options
options |= f.build.used_options options |= f.build.used_options
options &= f.options options &= f.options
@ -176,7 +176,7 @@ module Homebrew
fi = FormulaInstaller.new(f) fi = FormulaInstaller.new(f)
fi.options = options fi.options = options
fi.build_bottle = args.build_bottle? fi.build_bottle = args.build_bottle?
fi.installed_on_request = Homebrew.args.named.present? fi.installed_on_request = args.named.present?
fi.link_keg ||= keg_was_linked if keg_had_linked_opt fi.link_keg ||= keg_was_linked if keg_had_linked_opt
if tab if tab
fi.build_bottle ||= tab.built_bottle? fi.build_bottle ||= tab.built_bottle?

View File

@ -38,24 +38,23 @@ module Homebrew
description: "Show usage of <formula> by HEAD builds." description: "Show usage of <formula> by HEAD builds."
switch :debug switch :debug
conflicts "--devel", "--HEAD" conflicts "--devel", "--HEAD"
min_named :formula
end end
end end
def uses def uses
uses_args.parse uses_args.parse
raise FormulaUnspecifiedError if args.remaining.empty?
Formulary.enable_factory_cache! Formulary.enable_factory_cache!
used_formulae_missing = false used_formulae_missing = false
used_formulae = begin used_formulae = begin
Homebrew.args.formulae args.formulae
rescue FormulaUnavailableError => e rescue FormulaUnavailableError => e
opoo e opoo e
used_formulae_missing = true used_formulae_missing = true
# If the formula doesn't exist: fake the needed formula object name. # If the formula doesn't exist: fake the needed formula object name.
Homebrew.args.named.map { |name| OpenStruct.new name: name, full_name: name } args.named.map { |name| OpenStruct.new name: name, full_name: name }
end end
use_runtime_dependents = args.installed? && use_runtime_dependents = args.installed? &&