Skip to content
Snippets Groups Projects
Unverified Commit a7fe0ed8 authored by Mike McQuaid's avatar Mike McQuaid
Browse files

cmd: use more and cleanup new args APIs.

parent ad32d387
No related branches found
No related tags found
No related merge requests found
Showing
with 64 additions and 73 deletions
......@@ -26,10 +26,10 @@ module Homebrew
def __cache
__cache_args.parse
if ARGV.named.empty?
if args.no_named?
puts HOMEBREW_CACHE
else
Homebrew.args.formulae.each do |f|
args.formulae.each do |f|
if Fetch.fetch_bottle?(f)
puts f.bottle.cached_download
else
......
......@@ -22,10 +22,10 @@ module Homebrew
def __cellar
__cellar_args.parse
if Homebrew.args.named.blank?
if args.no_named?
puts HOMEBREW_CELLAR
else
puts Homebrew.args.resolved_formulae.map(&:rack)
puts args.resolved_formulae.map(&:rack)
end
end
end
......@@ -30,9 +30,8 @@ module Homebrew
__env_args.parse
ENV.activate_extensions!
ENV.deps = Homebrew.args.formulae if superenv?
ENV.deps = args.formulae if superenv?
ENV.setup_build_environment
ENV.universal_binary if ARGV.build_universal?
shell = if args.plain?
nil
......
......@@ -22,10 +22,10 @@ module Homebrew
def __prefix
__prefix_args.parse
if Homebrew.args.named.blank?
if args.no_named?
puts HOMEBREW_PREFIX
else
puts Homebrew.args.resolved_formulae.map { |f|
puts args.resolved_formulae.map { |f|
f.opt_prefix.exist? ? f.opt_prefix : f.installed_prefix
}
end
......
......@@ -20,10 +20,10 @@ module Homebrew
def __repository
__repository_args.parse
if ARGV.named.empty?
if args.no_named?
puts HOMEBREW_REPOSITORY
else
puts ARGV.named.map { |tap| Tap.fetch(tap).path }
puts args.named.map { |tap| Tap.fetch(tap).path }
end
end
end
......@@ -26,7 +26,7 @@ module Homebrew
def analytics
analytics_args.parse
case args.remaining.first
case args.named.first
when nil, "state"
if Utils::Analytics.disabled?
puts "Analytics are disabled."
......@@ -41,7 +41,7 @@ module Homebrew
when "regenerate-uuid"
Utils::Analytics.regenerate_uuid!
else
raise UsageError, "Unknown subcommand."
raise UsageError, "unknown subcommand"
end
end
end
......@@ -12,17 +12,12 @@ module Homebrew
Display the source of <formula>.
EOS
max_named 1
named :formula
end
end
def cat
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
pager = if ENV["HOMEBREW_BAT"].nil?
......@@ -30,6 +25,6 @@ module Homebrew
else
"#{HOMEBREW_PREFIX}/bin/bat"
end
safe_system pager, formulae.first.path, *Homebrew.args.passthrough
safe_system pager, args.formulae.first.path, *args.passthrough
end
end
......@@ -33,7 +33,7 @@ module Homebrew
def cleanup
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?
cleanup.prune_prefix_symlinks_and_directories
return
......
......@@ -15,15 +15,14 @@ module Homebrew
EOS
switch :verbose
switch :debug
min_named 1
end
end
def command
command_args.parse
raise UsageError, "This command requires a command argument" if args.remaining.empty?
args.remaining.each do |cmd|
args.named.each do |cmd|
path = Commands.path(cmd)
odie "Unknown command: #{cmd}" unless path
puts path
......
......@@ -62,7 +62,7 @@ module Homebrew
Formulary.enable_factory_cache!
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 &&
!args.include_build? &&
......@@ -74,27 +74,27 @@ module Homebrew
if args.installed?
puts_deps_tree Formula.installed.sort, recursive
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
return
elsif args.all?
puts_deps Formula.sort, recursive
return
elsif !Homebrew.args.remaining.empty? && args.for_each?
puts_deps Homebrew.args.formulae, recursive
elsif !args.no_named? && args.for_each?
puts_deps args.formulae, recursive
return
end
if Homebrew.args.remaining.empty?
if args.no_named?
raise FormulaUnspecifiedError unless args.installed?
puts_deps Formula.installed.sort, recursive
return
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.select!(&:installed?) if args.installed?
all_deps.map!(&method(:dep_display_name))
......
......@@ -40,16 +40,16 @@ module Homebrew
search_type << :either if args.search
search_type << :name if args.name
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?
raise FormulaUnspecifiedError if ARGV.named.empty?
raise FormulaUnspecifiedError if args.no_named?
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)
else
arg = ARGV.named.join(" ")
arg = args.named.join(" ")
string_or_regex = query_regexp(arg)
CacheStoreDatabase.use(:descriptions) do |db|
cache_store = DescriptionCacheStore.new(db)
......
......@@ -39,14 +39,14 @@ module Homebrew
exit
end
if ARGV.named.empty?
if args.no_named?
slow_checks = %w[
check_for_broken_symlinks
check_missing_deps
]
methods = (checks.all.sort - slow_checks) + slow_checks
else
methods = ARGV.named
methods = args.named
end
first_warning = true
......
......@@ -39,23 +39,22 @@ module Homebrew
switch :debug
conflicts "--devel", "--HEAD"
conflicts "--build-from-source", "--build-bottle", "--force-bottle"
min_named :formula
end
end
def fetch
fetch_args.parse
raise FormulaUnspecifiedError if ARGV.named.empty?
if args.deps?
bucket = []
Homebrew.args.formulae.each do |f|
args.formulae.each do |f|
bucket << f
bucket.concat f.recursive_dependencies.map(&:to_formula)
end
bucket.uniq!
else
bucket = Homebrew.args.formulae
bucket = args.formulae
end
puts "Fetching: #{bucket * ", "}" if bucket.size > 1
......
......@@ -142,10 +142,10 @@ module Homebrew
def gist_logs
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_build_from_source_checks(all_fatal: true)
gistify_logs(Homebrew.args.resolved_formulae.first)
gistify_logs(args.resolved_formulae.first)
end
end
......@@ -20,10 +20,10 @@ module Homebrew
def home
home_args.parse
if args.remaining.empty?
if args.no_named?
exec_browser HOMEBREW_WWW
else
exec_browser(*Homebrew.args.formulae.map(&:homepage))
exec_browser(*args.formulae.map(&:homepage))
end
end
end
......@@ -67,7 +67,7 @@ module Homebrew
end
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"
end
......@@ -77,23 +77,24 @@ module Homebrew
end
if 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"
raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
if !(args.all? || args.installed?) && args.no_named?
raise FormulaUnspecifiedError if args.no_named?
end
print_json
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
print_info
end
end
def print_info
if Homebrew.args.named.blank?
if args.no_named?
if args.analytics?
Utils::Analytics.output
elsif HOMEBREW_CELLAR.exist?
......@@ -101,7 +102,7 @@ module Homebrew
puts "#{count} #{"keg".pluralize(count)}, #{HOMEBREW_CELLAR.dup.abv}"
end
else
Homebrew.args.named.each_with_index do |f, i|
args.named.each_with_index do |f, i|
puts unless i.zero?
begin
formula = if f.include?("/") || File.exist?(f)
......@@ -135,7 +136,7 @@ module Homebrew
elsif args.installed?
Formula.installed.sort
else
Homebrew.args.formulae
args.formulae
end
json = ff.map(&:to_hash)
puts JSON.generate(json)
......
......@@ -88,13 +88,14 @@ module Homebrew
conflicts "--devel", "--HEAD"
conflicts "--build-from-source", "--build-bottle", "--force-bottle"
formula_options
min_named :formula
end
end
def install
install_args.parse
Homebrew.args.named.each do |name|
args.named.each do |name|
next if File.exist?(name)
next if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_CASK_REGEX
......@@ -102,8 +103,6 @@ module Homebrew
tap.install unless tap.installed?
end
raise FormulaUnspecifiedError if args.remaining.empty?
if args.ignore_dependencies?
opoo <<~EOS
#{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
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
if !Homebrew.args.HEAD? && f.stable.nil? && f.devel.nil?
if !args.HEAD? && f.stable.nil? && f.devel.nil?
raise <<~EOS
#{f.full_name} is a head-only formula
Install with `brew install --HEAD #{f.full_name}`
......
......@@ -25,20 +25,19 @@ module Homebrew
description: "Allow keg-only formulae to be linked."
switch :verbose
switch :debug
min_named :keg
end
end
def link
link_args.parse
raise KegUnspecifiedError if ARGV.named.empty?
mode = OpenStruct.new
mode.overwrite = true if args.overwrite?
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)
if keg.linked?
......
......@@ -55,14 +55,14 @@ module Homebrew
# Unbrewed uses the PREFIX, which will exist
# Things below use the CELLAR, which doesn't until the first formula is installed.
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
end
if args.pinned? || args.versions?
filtered_list
elsif Homebrew.args.named.blank?
elsif args.no_named?
if args.full_name?
full_names = Formula.installed.map(&:full_name).sort(&tap_and_name_comparison)
return if full_names.empty?
......@@ -70,12 +70,12 @@ module Homebrew
puts Formatter.columns(full_names)
else
ENV["CLICOLOR"] = nil
safe_system "ls", *Homebrew.args.passthrough << HOMEBREW_CELLAR
safe_system "ls", *args.passthrough << HOMEBREW_CELLAR
end
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
Homebrew.args.kegs.each { |keg| PrettyListing.new keg }
args.kegs.each { |keg| PrettyListing.new keg }
end
end
......@@ -123,10 +123,10 @@ module Homebrew
end
def filtered_list
names = if Homebrew.args.named.blank?
names = if args.no_named?
Formula.racks
else
racks = Homebrew.args.named.map { |n| Formulary.to_rack(n) }
racks = args.named.map { |n| Formulary.to_rack(n) }
racks.select do |rack|
Homebrew.failed = true unless rack.exist?
rack.exist?
......
......@@ -33,10 +33,10 @@ module Homebrew
# user path, too.
ENV["PATH"] = ENV["HOMEBREW_PATH"]
if ARGV.named.empty?
if args.no_named?
git_log HOMEBREW_REPOSITORY
else
path = Formulary.path(ARGV.named.first)
path = Formulary.path(args.named.first)
tap = Tap.from_path(path)
git_log path.dirname, path, tap
end
......@@ -62,8 +62,8 @@ module Homebrew
git -C "#{git_cd}" fetch --unshallow
EOS
end
args = Homebrew.args.options_only
args += ["--follow", "--", path] unless path.nil?
system "git", "log", *args
system_args = args.options_only
system_args += ["--follow", "--", path] if path.present?
system "git", "log", *system_args
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment