diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 7b05186e8c..17a008a778 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -50,7 +50,7 @@ begin help_flag = !ENV["HOMEBREW_HELP"].nil? cmd = nil - ARGV.dup.each_with_index do |arg, i| + ARGV.each_with_index do |arg, i| break if help_flag && cmd if arg == "help" && !cmd diff --git a/Library/Homebrew/cask/auditor.rb b/Library/Homebrew/cask/auditor.rb index 844fa8d9ee..db3cfa7317 100644 --- a/Library/Homebrew/cask/auditor.rb +++ b/Library/Homebrew/cask/auditor.rb @@ -38,7 +38,7 @@ module Cask end def audit - if !ARGV.value("language") && language_blocks + if !Homebrew.args.value("language") && language_blocks audit_all_languages else audit_cask_instance(cask) diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index 7d9f940d7c..ac5fd1875b 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -10,7 +10,7 @@ module Homebrew # undefine tap to allow --tap argument undef tap - def initialize(argv = ARGV.dup.freeze, set_default_args: false) + def initialize(argv = ARGV.freeze, set_default_args: false) super() @processed_options = [] @@ -177,6 +177,14 @@ module Homebrew formulae.any? { |args_f| args_f.full_name == f.full_name } end + def value(name) + arg_prefix = "--#{name}=" + flag_with_value = flags_only.find { |arg| arg.start_with?(arg_prefix) } + return unless flag_with_value + + flag_with_value.delete_prefix(arg_prefix) + end + private def option_to_name(option) diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 5486f464b8..8109bceee1 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -13,7 +13,7 @@ module Homebrew class Parser attr_reader :processed_options, :hide_from_man_page - def self.parse(argv = ARGV.dup.freeze, allow_no_named_args: false, &block) + def self.parse(argv = ARGV.freeze, allow_no_named_args: false, &block) new(argv, &block).parse(allow_no_named_args: allow_no_named_args) end @@ -38,7 +38,7 @@ module Homebrew } end - def initialize(argv = ARGV.dup.freeze, &block) + def initialize(argv = ARGV.freeze, &block) @parser = OptionParser.new @argv = argv @args = Homebrew::CLI::Args.new(@argv) diff --git a/Library/Homebrew/dev-cmd/irb.rb b/Library/Homebrew/dev-cmd/irb.rb index 56c164ec5f..e748e6fa19 100644 --- a/Library/Homebrew/dev-cmd/irb.rb +++ b/Library/Homebrew/dev-cmd/irb.rb @@ -19,7 +19,7 @@ module Homebrew def irb_args # work around IRB modifying ARGV. - Homebrew::CLI::Parser.new(ARGV.dup) do + Homebrew::CLI::Parser.new(ARGV.dup.freeze) do usage_banner <<~EOS `irb` [] diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb deleted file mode 100644 index 7e28311296..0000000000 --- a/Library/Homebrew/extend/ARGV.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module HomebrewArgvExtension - def value(name) - arg_prefix = "--#{name}=" - flag_with_value = find { |arg| arg.start_with?(arg_prefix) } - flag_with_value&.delete_prefix(arg_prefix) - end -end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index b5f3bc7746..da998b9e43 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -746,7 +746,7 @@ class FormulaInstaller formula.options.each do |opt| name = opt.name[/^([^=]+)=$/, 1] - value = ARGV.value(name) if name + value = Homebrew.args.value(name) if name args << "--#{name}=#{value}" if value end diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index b7067e7717..dbdca9a57c 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -35,13 +35,10 @@ require "env_config" require "config" require "os" -require "extend/ARGV" require "cli/args" require "messages" require "system_command" -ARGV.extend(HomebrewArgvExtension) - HOMEBREW_PRODUCT = ENV["HOMEBREW_PRODUCT"] HOMEBREW_VERSION = ENV["HOMEBREW_VERSION"] HOMEBREW_WWW = "https://brew.sh" diff --git a/Library/Homebrew/os/linux.rb b/Library/Homebrew/os/linux.rb index b295005c3a..c035191168 100644 --- a/Library/Homebrew/os/linux.rb +++ b/Library/Homebrew/os/linux.rb @@ -42,11 +42,7 @@ module OS end def languages - @languages ||= [ - *ARGV.value("language")&.split(","), - *ENV["HOMEBREW_LANGUAGES"]&.split(","), - *ENV["LANG"]&.slice(/[a-z]+/), - ].uniq + @languages ||= [*ENV["LANG"]&.slice(/[a-z]+/)].uniq end def language diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index 3118edf50f..4e77f0cf25 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -60,9 +60,11 @@ module OS def languages @languages ||= [ - *ARGV.value("language")&.split(","), + *Homebrew.args.value("language")&.split(","), *ENV["HOMEBREW_LANGUAGES"]&.split(","), - *Open3.capture2("defaults", "read", "-g", "AppleLanguages")[0].scan(/[^ \n"(),]+/), + *Open3.capture2("defaults", "read", "-g", "AppleLanguages") + .first + .scan(/[^ \n"(),]+/), ].uniq end diff --git a/Library/Homebrew/test/ARGV_spec.rb b/Library/Homebrew/test/ARGV_spec.rb deleted file mode 100644 index 01adb3a52f..0000000000 --- a/Library/Homebrew/test/ARGV_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require "extend/ARGV" - -describe HomebrewArgvExtension do - subject { argv.extend(described_class) } - - let(:argv) { ["mxcl"] } - - describe "#value" do - let(:argv) { ["--foo=", "--bar=ab"] } - - it "returns the value for a given string" do - expect(subject.value("foo")).to eq "" - expect(subject.value("bar")).to eq "ab" - end - - it "returns nil if there is no matching argument" do - expect(subject.value("baz")).to be nil - end - end -end diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb index 53fd117e03..cf15e5ba1a 100644 --- a/Library/Homebrew/test/formula_installer_spec.rb +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -48,8 +48,6 @@ describe FormulaInstaller do end specify "basic installation" do - ARGV << "--with-invalid_flag" # added to ensure it doesn't fail install - temporary_install(Testball.new) do |f| # Test that things made it into the Keg expect(f.prefix/"readme").to exist diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index f40e98cb25..fc3fbd8387 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -172,7 +172,6 @@ RSpec.configure do |config| @__files_before_test = find_files - @__argv = ARGV.dup @__env = ENV.to_hash # dup doesn't work on ENV @__stdout = $stdout.clone @@ -187,7 +186,6 @@ RSpec.configure do |config| rescue SystemExit => e raise "Unexpected exit with status #{e.status}." ensure - ARGV.replace(@__argv) ENV.replace(@__env) $stdout.reopen(@__stdout) diff --git a/Library/Homebrew/test/utils/bottles/collector_spec.rb b/Library/Homebrew/test/utils/bottles/collector_spec.rb index 91a1a25b34..5df7bd45a5 100644 --- a/Library/Homebrew/test/utils/bottles/collector_spec.rb +++ b/Library/Homebrew/test/utils/bottles/collector_spec.rb @@ -35,7 +35,7 @@ describe Utils::Bottles::Collector do end it "ignores HOMEBREW_SKIP_OR_LATER_BOTTLES on release versions", :needs_macos do - allow(ARGV).to receive(:skip_or_later_bottles?).and_return(true) + allow(Homebrew::EnvConfig).to receive(:skip_or_later_bottles?).and_return(true) allow(OS::Mac).to receive(:prerelease?).and_return(false) subject[:mavericks] = "foo" expect(subject.send(:find_matching_tag, :mavericks)).to eq(:mavericks) diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index c886ae1c2f..250cb00126 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "tab" -require "extend/ARGV" module Utils class Bottles