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