cli_args: Remove cyclic dependency on ARGV
This commit is contained in:
parent
22e25dd593
commit
28e62b52d1
@ -5,13 +5,14 @@ require "ostruct"
|
||||
module Homebrew
|
||||
module CLI
|
||||
class Args < OpenStruct
|
||||
attr_accessor :processed_options
|
||||
attr_accessor :processed_options, :args_parsed
|
||||
# undefine tap to allow --tap argument
|
||||
undef tap
|
||||
|
||||
def initialize(argv:)
|
||||
super
|
||||
@argv = argv
|
||||
@args_parsed = false
|
||||
@processed_options = []
|
||||
end
|
||||
|
||||
@ -132,7 +133,12 @@ module Homebrew
|
||||
|
||||
def downcased_unique_named
|
||||
# Only lowercase names, not paths, bottle filenames or URLs
|
||||
remaining.map do |arg|
|
||||
arguments = if args_parsed
|
||||
remaining
|
||||
else
|
||||
cmdline_args.reject { |arg| arg.start_with?("-") }
|
||||
end
|
||||
arguments.map do |arg|
|
||||
if arg.include?("/") || arg.end_with?(".tar.gz") || File.exist?(arg)
|
||||
arg
|
||||
else
|
||||
@ -141,10 +147,18 @@ module Homebrew
|
||||
end.uniq
|
||||
end
|
||||
|
||||
def head
|
||||
(args_parsed && HEAD?) || cmdline_args.include?("--HEAD")
|
||||
end
|
||||
|
||||
def devel
|
||||
(args_parsed && devel?) || cmdline_args.include?("--devel")
|
||||
end
|
||||
|
||||
def spec(default = :stable)
|
||||
if HEAD?
|
||||
if head
|
||||
:head
|
||||
elsif devel?
|
||||
elsif devel
|
||||
:devel
|
||||
else
|
||||
default
|
||||
|
||||
@ -13,7 +13,7 @@ module Homebrew
|
||||
attr_reader :processed_options, :hide_from_man_page
|
||||
|
||||
def self.parse(args = ARGV, &block)
|
||||
new(&block).parse(args)
|
||||
new(args, &block).parse(args)
|
||||
end
|
||||
|
||||
def self.global_options
|
||||
@ -25,10 +25,11 @@ module Homebrew
|
||||
}
|
||||
end
|
||||
|
||||
def initialize(&block)
|
||||
def initialize(args = ARGV, &block)
|
||||
@parser = OptionParser.new
|
||||
@args = Homebrew::CLI::Args.new(argv: ARGV_WITHOUT_MONKEY_PATCHING)
|
||||
@args[:remaining] = []
|
||||
@args[:cmdline_args] = args.dup
|
||||
@constraints = []
|
||||
@conflicts = []
|
||||
@switch_sources = {}
|
||||
@ -139,7 +140,7 @@ module Homebrew
|
||||
end
|
||||
check_constraint_violations
|
||||
@args[:remaining] = remaining_args
|
||||
@args_parsed = true
|
||||
@args.args_parsed = @args_parsed = true
|
||||
@args.processed_options = @processed_options
|
||||
Homebrew.args = @args
|
||||
cmdline_args.freeze
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user