Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove HomebrewArgvExtension #7638

Merged
merged 1 commit into from May 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/brew.rb
Expand Up @@ -50,7 +50,7 @@ def output_unsupported_error
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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/auditor.rb
Expand Up @@ -38,7 +38,7 @@ def check_token_conflicts?
end

def audit
if !ARGV.value("language") && language_blocks
if !Homebrew.args.value("language") && language_blocks
audit_all_languages
else
audit_cask_instance(cask)
Expand Down
10 changes: 9 additions & 1 deletion Library/Homebrew/cli/args.rb
Expand Up @@ -10,7 +10,7 @@ class Args < OpenStruct
# 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 = []
Expand Down Expand Up @@ -177,6 +177,14 @@ def include_formula_test_deps?(f)
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)
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cli/parser.rb
Expand Up @@ -13,7 +13,7 @@ module CLI
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

Expand All @@ -38,7 +38,7 @@ def self.global_options
}
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)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/irb.rb
Expand Up @@ -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` [<options>]

Expand Down
9 changes: 0 additions & 9 deletions Library/Homebrew/extend/ARGV.rb

This file was deleted.

2 changes: 1 addition & 1 deletion Library/Homebrew/formula_installer.rb
Expand Up @@ -746,7 +746,7 @@ def sanitized_argv_options

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

Expand Down
3 changes: 0 additions & 3 deletions Library/Homebrew/global.rb
Expand Up @@ -35,13 +35,10 @@

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"
Expand Down
6 changes: 1 addition & 5 deletions Library/Homebrew/os/linux.rb
Expand Up @@ -42,11 +42,7 @@ def full_version
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
Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/os/mac.rb
Expand Up @@ -60,9 +60,11 @@ def prerelease?

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

Expand Down
22 changes: 0 additions & 22 deletions Library/Homebrew/test/ARGV_spec.rb

This file was deleted.

2 changes: 0 additions & 2 deletions Library/Homebrew/test/formula_installer_spec.rb
Expand Up @@ -48,8 +48,6 @@ def temporary_install(formula)
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
Expand Down
2 changes: 0 additions & 2 deletions Library/Homebrew/test/spec_helper.rb
Expand Up @@ -172,7 +172,6 @@ def find_files

@__files_before_test = find_files

@__argv = ARGV.dup
@__env = ENV.to_hash # dup doesn't work on ENV

@__stdout = $stdout.clone
Expand All @@ -187,7 +186,6 @@ def find_files
rescue SystemExit => e
raise "Unexpected exit with status #{e.status}."
ensure
ARGV.replace(@__argv)
ENV.replace(@__env)

$stdout.reopen(@__stdout)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/utils/bottles/collector_spec.rb
Expand Up @@ -35,7 +35,7 @@
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)
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/utils/bottles.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "tab"
require "extend/ARGV"

module Utils
class Bottles
Expand Down