From 8d868b739c0deee523fc0db90b9476af83f2a7e8 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 18 Apr 2020 21:14:35 +0100 Subject: [PATCH] cli/args: simplify initialisation. Move some logic from `CLI::Parser` to `CLI::Args` to simplify and make more consistent the initialisation process. --- Library/Homebrew/cli/args.rb | 10 +++++----- Library/Homebrew/cli/parser.rb | 7 +++---- Library/Homebrew/global.rb | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index ff6afae43f..1b00c1445b 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -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 diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 07d05246f2..b5d6941d30 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -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 = {} diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 78003daf96..1fc0cb0a54 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -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