From bc27e38f1825cc1114c276359fe3db3a2e5e5e63 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 23 May 2020 14:03:43 +0100 Subject: [PATCH] Remove ARGV.debug? Replace with `Homebrew.args.debug?`. Part of #5730. --- Library/Homebrew/brew.rb | 8 ++-- Library/Homebrew/build.rb | 2 +- Library/Homebrew/cask/cmd.rb | 2 +- Library/Homebrew/cleaner.rb | 2 +- Library/Homebrew/extend/ARGV.rb | 46 ------------------ Library/Homebrew/formula.rb | 4 +- Library/Homebrew/formula_installer.rb | 2 +- Library/Homebrew/formula_versions.rb | 2 +- Library/Homebrew/formulary.rb | 4 +- Library/Homebrew/migrator.rb | 4 +- Library/Homebrew/os/mac/keg.rb | 4 +- Library/Homebrew/style.rb | 2 +- Library/Homebrew/system_command.rb | 2 +- Library/Homebrew/test/ARGV_spec.rb | 67 --------------------------- Library/Homebrew/utils.rb | 2 +- 15 files changed, 20 insertions(+), 133 deletions(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index b141390a0f100..7b05186e8c776 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -139,8 +139,8 @@ def output_unsupported_error require "help" Homebrew::Help.help cmd, usage_error: e.message rescue SystemExit => e - onoe "Kernel.exit" if ARGV.debug? && !e.success? - $stderr.puts e.backtrace if ARGV.debug? + onoe "Kernel.exit" if Homebrew.args.debug? && !e.success? + $stderr.puts e.backtrace if Homebrew.args.debug? raise rescue Interrupt $stderr.puts # seemingly a newline is typical @@ -156,7 +156,7 @@ def output_unsupported_error raise if e.message.empty? onoe e - $stderr.puts e.backtrace if ARGV.debug? + $stderr.puts e.backtrace if Homebrew.args.debug? output_unsupported_error if Homebrew.args.HEAD? @@ -167,7 +167,7 @@ def output_unsupported_error $stderr.puts "If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):" $stderr.puts " #{Formatter.url(e.issues_url)}" end - $stderr.puts e.backtrace if ARGV.debug? + $stderr.puts e.backtrace if Homebrew.args.debug? exit 1 rescue Exception => e # rubocop:disable Lint/RescueException onoe e diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index f9fd51a250b33..bd1a68614c001 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -116,7 +116,7 @@ def install } with_env(new_env) do - formula.extend(Debrew::Formula) if ARGV.debug? + formula.extend(Debrew::Formula) if Homebrew.args.debug? formula.update_head_version diff --git a/Library/Homebrew/cask/cmd.rb b/Library/Homebrew/cask/cmd.rb index 8e93128b32317..ce0562d87cad7 100644 --- a/Library/Homebrew/cask/cmd.rb +++ b/Library/Homebrew/cask/cmd.rb @@ -151,7 +151,7 @@ def run end rescue CaskError, MethodDeprecatedError, ArgumentError, OptionParser::InvalidOption => e onoe e.message - $stderr.puts e.backtrace if ARGV.debug? + $stderr.puts e.backtrace if Homebrew.args.debug? exit 1 rescue StandardError, ScriptError, NoMemoryError => e onoe e.message diff --git a/Library/Homebrew/cleaner.rb b/Library/Homebrew/cleaner.rb index c469f8f277440..cf962341f717b 100644 --- a/Library/Homebrew/cleaner.rb +++ b/Library/Homebrew/cleaner.rb @@ -109,7 +109,7 @@ def clean_dir(d) else 0444 end - if ARGV.debug? + if Homebrew.args.debug? old_perms = path.stat.mode & 0777 odebug "Fixing #{path} permissions from #{old_perms.to_s(8)} to #{perms.to_s(8)}" if perms != old_perms end diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb index 7b2a6fa32bd39..7e28311296b46 100644 --- a/Library/Homebrew/extend/ARGV.rb +++ b/Library/Homebrew/extend/ARGV.rb @@ -6,50 +6,4 @@ def value(name) flag_with_value = find { |arg| arg.start_with?(arg_prefix) } flag_with_value&.delete_prefix(arg_prefix) end - - def debug? - flag?("--debug") || !ENV["HOMEBREW_DEBUG"].nil? - end - - private - - def options_only - select { |arg| arg.start_with?("-") } - end - - def flag?(flag) - options_only.include?(flag) || switch?(flag[2, 1]) - end - - # e.g. `foo -ns -i --bar` has three switches: `n`, `s` and `i` - def switch?(char) - return false if char.length > 1 - - options_only.any? { |arg| arg.scan("-").size == 1 && arg.include?(char) } - end - - def spec(default = :stable) - if include?("--HEAD") - :head - elsif include?("--devel") - :devel - else - default - end - end - - def named - self - options_only - end - - def downcased_unique_named - # Only lowercase names, not paths, bottle filenames or URLs - named.map do |arg| - if arg.include?("/") || arg.end_with?(".tar.gz") || File.exist?(arg) - arg - else - arg.downcase - end - end.uniq - end end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 9b62f60c85f42..faaaf2d61d7bf 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1172,7 +1172,7 @@ def brew(fetch: true) begin yield self, staging rescue - staging.retain! if Homebrew.args.interactive? || ARGV.debug? + staging.retain! if Homebrew.args.interactive? || Homebrew.args.debug? raise ensure cp Dir["config.log", "CMakeCache.txt"], logs @@ -1822,7 +1822,7 @@ def run_test end end rescue Exception # rubocop:disable Lint/RescueException - staging.retain! if ARGV.debug? + staging.retain! if Homebrew.args.debug? raise end end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index c856663435161..b5f3bc774659f 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -59,7 +59,7 @@ def initialize(formula) @git = false @verbose = Homebrew.args.verbose? @quiet = Homebrew.args.quiet? - @debug = ARGV.debug? + @debug = Homebrew.args.debug? @installed_as_dependency = false @installed_on_request = true @options = Options.new diff --git a/Library/Homebrew/formula_versions.rb b/Library/Homebrew/formula_versions.rb index a30313846c7c9..1f8c3c19c3526 100644 --- a/Library/Homebrew/formula_versions.rb +++ b/Library/Homebrew/formula_versions.rb @@ -44,7 +44,7 @@ def formula_at_revision(rev) rescue *IGNORED_EXCEPTIONS => e # We rescue these so that we can skip bad versions and # continue walking the history - odebug "#{e} in #{name} at revision #{rev}", e.backtrace if ARGV.debug? + odebug "#{e} in #{name} at revision #{rev}", e.backtrace if Homebrew.args.debug? rescue FormulaUnavailableError nil ensure diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 8448a1298d895..d71515ae7f901 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -130,7 +130,7 @@ def klass private def load_file - $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if ARGV.debug? + $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if Homebrew.args.debug? raise FormulaUnavailableError, name unless path.file? Formulary.load_formula_from_path(name, path) @@ -302,7 +302,7 @@ def initialize(name, path, contents) end def klass - $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if ARGV.debug? + $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if Homebrew.args.debug? namespace = "FormulaNamespace#{Digest::MD5.hexdigest(contents)}" Formulary.load_formula(name, path, contents, namespace) end diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index 7b393d512743b..3329e164bc988 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -209,7 +209,7 @@ def migrate rescue Exception => e # rubocop:disable Lint/RescueException onoe "Error occurred while migrating." puts e - puts e.backtrace if ARGV.debug? + puts e.backtrace if Homebrew.args.debug? puts "Backing up..." ignore_interrupts { backup_oldname } ensure @@ -318,7 +318,7 @@ def link_newname rescue Exception => e # rubocop:disable Lint/RescueException onoe "An unexpected error occurred during linking" puts e - puts e.backtrace if ARGV.debug? + puts e.backtrace if Homebrew.args.debug? ignore_interrupts { new_keg.unlink } raise end diff --git a/Library/Homebrew/os/mac/keg.rb b/Library/Homebrew/os/mac/keg.rb index 9cf35e39d9215..90593712ff7c7 100644 --- a/Library/Homebrew/os/mac/keg.rb +++ b/Library/Homebrew/os/mac/keg.rb @@ -5,7 +5,7 @@ def change_dylib_id(id, file) return if file.dylib_id == id @require_relocation = true - odebug "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}" if ARGV.debug? + odebug "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}" if Homebrew.args.debug? MachO::Tools.change_dylib_id(file, id, strict: false) rescue MachO::MachOError onoe <<~EOS @@ -20,7 +20,7 @@ def change_install_name(old, new, file) return if old == new @require_relocation = true - odebug "Changing install name in #{file}\n from #{old}\n to #{new}" if ARGV.debug? + odebug "Changing install name in #{file}\n from #{old}\n to #{new}" if Homebrew.args.debug? MachO::Tools.change_install_name(file, old, new, strict: false) rescue MachO::MachOError onoe <<~EOS diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index 4c2c57d0ec749..9ed95d53e8e7c 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -77,7 +77,7 @@ def check_style_impl(files, output_type, fix: false, except_cops: nil, only_cops case output_type when :print - args << "--debug" if ARGV.debug? + args << "--debug" if Homebrew.args.debug? args << "--display-cop-names" if Homebrew.args.display_cop_names? args << "--format" << "simple" if files system(cache_env, "rubocop", *args) diff --git a/Library/Homebrew/system_command.rb b/Library/Homebrew/system_command.rb index f21fa78e4c5c5..fb05c7bd8b135 100644 --- a/Library/Homebrew/system_command.rb +++ b/Library/Homebrew/system_command.rb @@ -34,7 +34,7 @@ def self.run!(command, **options) end def run! - puts redact_secrets(command.shelljoin.gsub('\=', "="), @secrets) if verbose? || ARGV.debug? + puts redact_secrets(command.shelljoin.gsub('\=', "="), @secrets) if verbose? || Homebrew.args.debug? @output = [] diff --git a/Library/Homebrew/test/ARGV_spec.rb b/Library/Homebrew/test/ARGV_spec.rb index dd1699af31217..01adb3a52f987 100644 --- a/Library/Homebrew/test/ARGV_spec.rb +++ b/Library/Homebrew/test/ARGV_spec.rb @@ -7,73 +7,6 @@ let(:argv) { ["mxcl"] } - describe "#named" do - let(:argv) { ["foo", "--debug", "-v"] } - - it "returns an array of non-option arguments" do - expect(subject.send(:named)).to eq ["foo"] - end - - context "when there are no named arguments" do - let(:argv) { [] } - - it "returns an empty array" do - expect(subject.send(:named)).to be_empty - end - end - end - - describe "#options_only" do - let(:argv) { ["--foo", "-vds", "a", "b", "cdefg"] } - - it "returns an array of option arguments" do - expect(subject.send("options_only")).to eq ["--foo", "-vds"] - end - end - - describe "#empty?" do - let(:argv) { [] } - - it "returns true if it is empty" do - expect(subject).to be_empty - end - end - - describe "#switch?" do - let(:argv) { ["-ns", "-i", "--bar", "-a-bad-arg"] } - - it "returns true if the given string is a switch" do - %w[n s i].each do |s| - expect(subject.send("switch?", s)).to be true - end - end - - it "returns false if the given string is not a switch" do - %w[b ns bar --bar -n a bad arg].each do |s| - expect(subject.send("switch?", s)).to be false - end - end - end - - describe "#flag?" do - let(:argv) { ["--foo", "-bq", "--bar"] } - - it "returns true if the given string is a flag" do - expect(subject.send("flag?", "--foo")).to eq true - expect(subject.send("flag?", "--bar")).to eq true - end - - it "returns true if there is a switch with the same initial character" do - expect(subject.send("flag?", "--baz")).to eq true - expect(subject.send("flag?", "--qux")).to eq true - end - - it "returns false if there is no matching flag" do - expect(subject.send("flag?", "--frotz")).to eq false - expect(subject.send("flag?", "--debug")).to eq false - end - end - describe "#value" do let(:argv) { ["--foo=", "--bar=ab"] } diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index b440a9553f8b3..4f099ceada261 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -96,7 +96,7 @@ def ohai(title, *sput) end def odebug(title, *sput) - return unless ARGV.debug? + return unless Homebrew.args.debug? puts Formatter.headline(title, color: :magenta) puts sput unless sput.empty?