cli/args: simplify initialisation.

Move some logic from `CLI::Parser` to `CLI::Args` to simplify and make
more consistent the initialisation process.
This commit is contained in:
Mike McQuaid 2020-04-18 21:14:35 +01:00
parent b05c72b98b
commit 8d868b739c
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
3 changed files with 9 additions and 10 deletions

View File

@ -9,10 +9,12 @@ module Homebrew
# undefine tap to allow --tap argument # undefine tap to allow --tap argument
undef tap undef tap
def initialize(argv:) def initialize
super super
@argv = argv
@cmdline_args = argv self[:remaining] = []
self[:cmdline_args] = ARGV_WITHOUT_MONKEY_PATCHING.dup
@args_parsed = false @args_parsed = false
@processed_options = [] @processed_options = []
end end
@ -60,8 +62,6 @@ module Homebrew
end end
def named def named
return [] if remaining.nil?
remaining remaining
end end

View File

@ -37,11 +37,10 @@ module Homebrew
} }
end end
def initialize(args = ARGV, &block) def initialize(&block)
@parser = OptionParser.new @parser = OptionParser.new
@args = Homebrew::CLI::Args.new(argv: ARGV_WITHOUT_MONKEY_PATCHING) @args = Homebrew::CLI::Args.new
@args[:remaining] = []
@args[:cmdline_args] = args.dup
@constraints = [] @constraints = []
@conflicts = [] @conflicts = []
@switch_sources = {} @switch_sources = {}

View File

@ -86,7 +86,7 @@ module Homebrew
end end
def args def args
@args ||= CLI::Args.new(argv: ARGV_WITHOUT_MONKEY_PATCHING) @args ||= CLI::Args.new
end end
def messages def messages