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 ARGV.debug? #7637

Merged
merged 1 commit into from May 23, 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
8 changes: 4 additions & 4 deletions Library/Homebrew/brew.rb
Expand Up @@ -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
Expand All @@ -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?

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/build.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/cmd.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cleaner.rb
Expand Up @@ -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
Expand Down
46 changes: 0 additions & 46 deletions Library/Homebrew/extend/ARGV.rb
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Library/Homebrew/formula.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula_installer.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula_versions.rb
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/formulary.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/migrator.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/os/mac/keg.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/style.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/system_command.rb
Expand Up @@ -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 = []

Expand Down
67 changes: 0 additions & 67 deletions Library/Homebrew/test/ARGV_spec.rb
Expand Up @@ -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"] }

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/utils.rb
Expand Up @@ -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?
Expand Down