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
undef tap
def initialize(argv:)
def initialize
super
@argv = argv
@cmdline_args = argv
self[:remaining] = []
self[:cmdline_args] = ARGV_WITHOUT_MONKEY_PATCHING.dup
@args_parsed = false
@processed_options = []
end
@ -60,8 +62,6 @@ module Homebrew
end
def named
return [] if remaining.nil?
remaining
end

View File

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

View File

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