argv: move formulae to cli/args
This commit is contained in:
parent
bacb3d0e7e
commit
22e25dd593
@ -51,22 +51,36 @@ module Homebrew
|
||||
options_only - CLI::Parser.global_options.values.map(&:first).flatten
|
||||
end
|
||||
|
||||
def downcased_unique_named
|
||||
# Only lowercase names, not paths, bottle filenames or URLs
|
||||
@downcased_unique_named ||= remaining.map do |arg|
|
||||
if arg.include?("/") || arg.end_with?(".tar.gz") || File.exist?(arg)
|
||||
arg
|
||||
def named
|
||||
remaining
|
||||
end
|
||||
|
||||
def formulae
|
||||
require "formula"
|
||||
@formulae ||= (downcased_unique_named - casks).map do |name|
|
||||
if name.include?("/") || File.exist?(name)
|
||||
Formulary.factory(name, spec)
|
||||
else
|
||||
arg.downcase
|
||||
Formulary.find_with_priority(name, spec)
|
||||
end
|
||||
end.uniq
|
||||
end.uniq(&:name)
|
||||
end
|
||||
|
||||
def resolved_formulae
|
||||
require "formula"
|
||||
@resolved_formulae ||= (downcased_unique_named - casks).map do |name|
|
||||
Formulary.resolve(name, spec: spec(nil))
|
||||
end.uniq(&:name)
|
||||
end
|
||||
|
||||
def casks
|
||||
@casks ||= downcased_unique_named.grep HOMEBREW_CASK_TAP_CASK_REGEX
|
||||
end
|
||||
|
||||
def kegs
|
||||
require "keg"
|
||||
require "formula"
|
||||
require "missing_formula"
|
||||
|
||||
@kegs ||= downcased_unique_named.map do |name|
|
||||
raise UsageError if name.empty?
|
||||
|
||||
@ -113,6 +127,29 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def downcased_unique_named
|
||||
# Only lowercase names, not paths, bottle filenames or URLs
|
||||
remaining.map do |arg|
|
||||
if arg.include?("/") || arg.end_with?(".tar.gz") || File.exist?(arg)
|
||||
arg
|
||||
else
|
||||
arg.downcase
|
||||
end
|
||||
end.uniq
|
||||
end
|
||||
|
||||
def spec(default = :stable)
|
||||
if HEAD?
|
||||
:head
|
||||
elsif devel?
|
||||
:devel
|
||||
else
|
||||
default
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -28,6 +28,7 @@ module Homebrew
|
||||
def initialize(&block)
|
||||
@parser = OptionParser.new
|
||||
@args = Homebrew::CLI::Args.new(argv: ARGV_WITHOUT_MONKEY_PATCHING)
|
||||
@args[:remaining] = []
|
||||
@constraints = []
|
||||
@conflicts = []
|
||||
@switch_sources = {}
|
||||
@ -159,7 +160,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
def formula_options
|
||||
ARGV.formulae.each do |f|
|
||||
@args.formulae.each do |f|
|
||||
next if f.options.empty?
|
||||
|
||||
f.options.each do |o|
|
||||
|
@ -29,7 +29,7 @@ module Homebrew
|
||||
if ARGV.named.empty?
|
||||
puts HOMEBREW_CACHE
|
||||
else
|
||||
ARGV.formulae.each do |f|
|
||||
Homebrew.args.formulae.each do |f|
|
||||
if Fetch.fetch_bottle?(f)
|
||||
puts f.bottle.cached_download
|
||||
else
|
||||
|
@ -30,7 +30,7 @@ module Homebrew
|
||||
__env_args.parse
|
||||
|
||||
ENV.activate_extensions!
|
||||
ENV.deps = ARGV.formulae if superenv?
|
||||
ENV.deps = Homebrew.args.formulae if superenv?
|
||||
ENV.setup_build_environment
|
||||
ENV.universal_binary if ARGV.build_universal?
|
||||
|
||||
|
@ -20,7 +20,7 @@ module Homebrew
|
||||
# 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 = ARGV.formulae
|
||||
formulae = Homebrew.args.formulae
|
||||
raise FormulaUnspecifiedError if formulae.empty?
|
||||
raise "`brew cat` doesn't support multiple arguments" if args.remaining.size > 1
|
||||
|
||||
|
@ -67,16 +67,16 @@ module Homebrew
|
||||
if args.installed?
|
||||
puts_deps_tree Formula.installed.sort, recursive
|
||||
else
|
||||
raise FormulaUnspecifiedError if args.remaining.empty?
|
||||
raise FormulaUnspecifiedError if Homebrew.args.remaining.empty?
|
||||
|
||||
puts_deps_tree ARGV.formulae, recursive
|
||||
puts_deps_tree Homebrew.args.formulae, recursive
|
||||
end
|
||||
return
|
||||
elsif args.all?
|
||||
puts_deps Formula.sort, recursive
|
||||
return
|
||||
elsif !args.remaining.empty? && args.for_each?
|
||||
puts_deps ARGV.formulae, recursive
|
||||
elsif !Homebrew.args.remaining.empty? && args.for_each?
|
||||
puts_deps Homebrew.args.formulae, recursive
|
||||
return
|
||||
end
|
||||
|
||||
@ -88,14 +88,14 @@ module Homebrew
|
||||
!args.include_optional? &&
|
||||
!args.skip_recommended?
|
||||
|
||||
if args.remaining.empty?
|
||||
if Homebrew.args.remaining.empty?
|
||||
raise FormulaUnspecifiedError unless args.installed?
|
||||
|
||||
puts_deps Formula.installed.sort, recursive
|
||||
return
|
||||
end
|
||||
|
||||
all_deps = deps_for_formulae(ARGV.formulae, recursive, &(args.union? ? :| : :&))
|
||||
all_deps = deps_for_formulae(Homebrew.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))
|
||||
|
@ -50,7 +50,7 @@ module Homebrew
|
||||
raise FormulaUnspecifiedError if ARGV.named.empty?
|
||||
|
||||
desc = {}
|
||||
ARGV.formulae.each { |f| desc[f.full_name] = f.desc }
|
||||
Homebrew.args.formulae.each { |f| desc[f.full_name] = f.desc }
|
||||
Descriptions.new(desc)
|
||||
else
|
||||
arg = ARGV.named.join(" ")
|
||||
|
@ -49,13 +49,13 @@ module Homebrew
|
||||
|
||||
if args.deps?
|
||||
bucket = []
|
||||
ARGV.formulae.each do |f|
|
||||
Homebrew.args.formulae.each do |f|
|
||||
bucket << f
|
||||
bucket.concat f.recursive_dependencies.map(&:to_formula)
|
||||
end
|
||||
bucket.uniq!
|
||||
else
|
||||
bucket = ARGV.formulae
|
||||
bucket = Homebrew.args.formulae
|
||||
end
|
||||
|
||||
puts "Fetching: #{bucket * ", "}" if bucket.size > 1
|
||||
|
@ -23,7 +23,7 @@ module Homebrew
|
||||
if args.remaining.empty?
|
||||
exec_browser HOMEBREW_WWW
|
||||
else
|
||||
exec_browser(*ARGV.formulae.map(&:homepage))
|
||||
exec_browser(*Homebrew.args.formulae.map(&:homepage))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -80,7 +80,7 @@ module Homebrew
|
||||
|
||||
print_json
|
||||
elsif args.github?
|
||||
exec_browser(*ARGV.formulae.map { |f| github_info(f) })
|
||||
exec_browser(*Homebrew.args.formulae.map { |f| github_info(f) })
|
||||
else
|
||||
print_info
|
||||
end
|
||||
@ -129,7 +129,7 @@ module Homebrew
|
||||
elsif args.installed?
|
||||
Formula.installed.sort
|
||||
else
|
||||
ARGV.formulae
|
||||
Homebrew.args.formulae
|
||||
end
|
||||
json = ff.map(&:to_hash)
|
||||
puts JSON.generate(json)
|
||||
|
@ -130,7 +130,7 @@ module Homebrew
|
||||
# developer tools are available, we need to stop them early on
|
||||
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
|
||||
|
||||
ARGV.formulae.each do |f|
|
||||
Homebrew.args.formulae.each do |f|
|
||||
# head-only without --HEAD is an error
|
||||
if !Homebrew.args.HEAD? && f.stable.nil? && f.devel.nil?
|
||||
raise <<~EOS
|
||||
|
@ -35,7 +35,7 @@ module Homebrew
|
||||
else
|
||||
raise FormulaUnspecifiedError if args.remaining.empty?
|
||||
|
||||
puts_options ARGV.formulae
|
||||
puts_options Homebrew.args.formulae
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -45,7 +45,7 @@ module Homebrew
|
||||
elsif ARGV.named.any? { |tap| tap.count("/") == 1 }
|
||||
ARGV.named.map { |tap| Tap.fetch(tap).path }
|
||||
else
|
||||
ARGV.formulae.map(&:path)
|
||||
Homebrew.args.formulae.map(&:path)
|
||||
end
|
||||
|
||||
only_cops = args.only_cops
|
||||
|
@ -32,7 +32,7 @@ module Homebrew
|
||||
def unpack
|
||||
unpack_args.parse
|
||||
|
||||
formulae = ARGV.formulae
|
||||
formulae = Homebrew.args.formulae
|
||||
raise FormulaUnspecifiedError if formulae.empty?
|
||||
|
||||
if dir = args.destdir
|
||||
|
@ -50,7 +50,7 @@ module Homebrew
|
||||
|
||||
used_formulae_missing = false
|
||||
used_formulae = begin
|
||||
ARGV.formulae
|
||||
Homebrew.args.formulae
|
||||
rescue FormulaUnavailableError => e
|
||||
opoo e
|
||||
used_formulae_missing = true
|
||||
|
@ -114,7 +114,7 @@ module Homebrew
|
||||
# Use the user's browser, too.
|
||||
ENV["BROWSER"] = ENV["HOMEBREW_BROWSER"]
|
||||
|
||||
formula = ARGV.formulae.first
|
||||
formula = Homebrew.args.formulae.first
|
||||
|
||||
if formula
|
||||
tap_full_name, origin_branch, previous_branch = use_correct_linux_tap(formula)
|
||||
|
@ -32,10 +32,11 @@ module Homebrew
|
||||
# user path, too.
|
||||
ENV["PATH"] = ENV["HOMEBREW_PATH"]
|
||||
|
||||
raise FormulaUnspecifiedError if ARGV.formulae.empty?
|
||||
raise "Multiple formulae given, only one is allowed." if ARGV.formulae.length > 1
|
||||
formulae = Homebrew.args.formulae
|
||||
raise FormulaUnspecifiedError if formulae.empty?
|
||||
raise "Multiple formulae given, only one is allowed." if formulae.length > 1
|
||||
|
||||
formula = ARGV.formulae.first
|
||||
formula = formulae.first
|
||||
current_revision = formula.revision
|
||||
|
||||
if current_revision.zero?
|
||||
|
@ -27,7 +27,7 @@ module Homebrew
|
||||
bintray_key = ENV["HOMEBREW_BINTRAY_KEY"]
|
||||
raise "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" if !bintray_user || !bintray_key
|
||||
|
||||
ARGV.formulae.each do |f|
|
||||
Homebrew.args.formulae.each do |f|
|
||||
bintray_package = Utils::Bottles::Bintray.package f.name
|
||||
bintray_repo_url = "https://api.bintray.com/packages/homebrew/mirror"
|
||||
package_url = "#{bintray_repo_url}/#{bintray_package}"
|
||||
|
@ -236,6 +236,21 @@ describe Homebrew::CLI::Parser do
|
||||
expect(Homebrew.args.passthrough).to eq %w[--foo --bar=value -s]
|
||||
end
|
||||
|
||||
it "#formulae raises an error when a Formula is unavailable" do
|
||||
parser.parse(["mxcl"])
|
||||
expect { Homebrew.args.formulae }.to raise_error FormulaUnavailableError
|
||||
end
|
||||
|
||||
it "#formulae returns an empty array when there are no Formulae" do
|
||||
parser.parse([])
|
||||
expect(Homebrew.args.formulae).to be_empty
|
||||
end
|
||||
|
||||
it "#casks returns an empty array when there are no matching casks" do
|
||||
parser.parse([])
|
||||
expect(Homebrew.args.casks).to eq []
|
||||
end
|
||||
|
||||
context "kegs" do
|
||||
before do
|
||||
keg = HOMEBREW_CELLAR + "mxcl/10.0"
|
||||
@ -252,5 +267,15 @@ describe Homebrew::CLI::Parser do
|
||||
expect(Homebrew.args.kegs).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
it "#named returns an array of non-option arguments" do
|
||||
parser.parse(["foo", "-v", "-s"])
|
||||
expect(Homebrew.args.named).to eq ["foo"]
|
||||
end
|
||||
|
||||
it "#named returns an empty array when there are no named arguments" do
|
||||
parser.parse([])
|
||||
expect(Homebrew.args.named).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user