From acde828a45c452b54413a3cd711752343e54f3cf Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sat, 1 Feb 2020 13:32:39 +0100 Subject: [PATCH] ARGV: Replace ARGV.verbose? with Homebrew.args.verbose? --- Library/Homebrew/cleaner.rb | 2 +- Library/Homebrew/cli/parser.rb | 6 +++++- Library/Homebrew/download_strategy.rb | 10 +++++----- Library/Homebrew/exceptions.rb | 2 +- Library/Homebrew/extend/pathname.rb | 4 ++-- Library/Homebrew/formula.rb | 4 ++-- Library/Homebrew/formula_installer.rb | 2 +- Library/Homebrew/keg.rb | 6 ++++-- Library/Homebrew/resource.rb | 2 +- Library/Homebrew/sandbox.rb | 2 +- Library/Homebrew/style.rb | 2 +- Library/Homebrew/system_command.rb | 2 +- Library/Homebrew/test/rubocops/lines_spec.rb | 2 +- Library/Homebrew/test/system_command_result_spec.rb | 4 ++-- Library/Homebrew/utils.rb | 8 ++++---- Library/Homebrew/utils/curl.rb | 2 +- 16 files changed, 33 insertions(+), 27 deletions(-) diff --git a/Library/Homebrew/cleaner.rb b/Library/Homebrew/cleaner.rb index 9ff56ce26c..c469f8f277 100644 --- a/Library/Homebrew/cleaner.rb +++ b/Library/Homebrew/cleaner.rb @@ -58,7 +58,7 @@ class Cleaner # actual files gets removed correctly. dirs.reverse_each do |d| if d.children.empty? - puts "rmdir: #{d} (empty)" if ARGV.verbose? + puts "rmdir: #{d} (empty)" if Homebrew.args.verbose? d.rmdir end end diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index e43620a0cf..58e8024dc4 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -64,10 +64,14 @@ module Homebrew set_constraints(name, required_for: required_for, depends_on: depends_on) end - enable_switch(*names, from: :env) if !env.nil? && !ENV["HOMEBREW_#{env.to_s.upcase}"].nil? + enable_switch(*names, from: :env) if env?(env) end alias switch_option switch + def env?(env) + env.present? && ENV["HOMEBREW_#{env.to_s.upcase}"].present? + end + def usage_banner(text) @parser.banner = Formatter.wrap("#{text}\n", COMMAND_DESC_WIDTH) end diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 58b78ec499..166a1b3340 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -60,7 +60,7 @@ class AbstractDownloadStrategy ref_type: @ref_type, ref: @ref) .extract_nestedly(basename: basename, prioritise_extension: true, - verbose: ARGV.verbose? && !shutup) + verbose: Homebrew.args.verbose? && !shutup) chdir end @@ -104,7 +104,7 @@ class AbstractDownloadStrategy *args, print_stdout: !shutup, print_stderr: !shutup, - verbose: ARGV.verbose? && !shutup, + verbose: Homebrew.args.verbose? && !shutup, env: env, **options, ) @@ -497,7 +497,7 @@ class NoUnzipCurlDownloadStrategy < CurlDownloadStrategy def stage UnpackStrategy::Uncompressed.new(cached_location) .extract(basename: basename, - verbose: ARGV.verbose? && !shutup) + verbose: Homebrew.args.verbose? && !shutup) end end @@ -552,7 +552,7 @@ class SubversionDownloadStrategy < VCSDownloadStrategy # This saves on bandwidth and will have a similar effect to verifying the # cache as it will make any changes to get the right revision. args = [] - args << "--quiet" unless ARGV.verbose? + args << "--quiet" unless Homebrew.args.verbose? if revision ohai "Checking out #{@ref}" @@ -896,7 +896,7 @@ class CVSDownloadStrategy < VCSDownloadStrategy end def quiet_flag - "-Q" unless ARGV.verbose? + "-Q" unless Homebrew.args.verbose? end def clone_repo diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 00cdf04d7a..55fa41db68 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -381,7 +381,7 @@ class BuildError < RuntimeError def dump puts - if ARGV.verbose? + if Homebrew.args.verbose? require "system_config" require "build_environment" diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 1ad0ff96a6..98a8cfc1b1 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -443,8 +443,8 @@ module ObserverPathnameExtension MAXIMUM_VERBOSE_OUTPUT = 100 def verbose? - return ARGV.verbose? unless ENV["CI"] - return false unless ARGV.verbose? + return Homebrew.args.verbose? unless ENV["CI"] + return false unless Homebrew.args.verbose? if total < MAXIMUM_VERBOSE_OUTPUT true diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 29e613fdd3..0d3146d9ef 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -506,7 +506,7 @@ class Formula return false unless head&.downloader.is_a?(VCSDownloadStrategy) downloader = head.downloader - downloader.shutup! unless ARGV.verbose? + downloader.shutup! unless Homebrew.args.verbose? downloader.commit_outdated?(version.version.commit) end @@ -1844,7 +1844,7 @@ class Formula # # If there is a "make", "install" available, please use it! # system "make", "install" def system(cmd, *args) - verbose = ARGV.verbose? + verbose = Homebrew.args.verbose? verbose_using_dots = !ENV["HOMEBREW_VERBOSE_USING_DOTS"].nil? # remove "boring" arguments so that the important ones are more likely to diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 36e610ae5e..54bcff744d 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -56,7 +56,7 @@ class FormulaInstaller @include_test = ARGV.include?("--include-test") @interactive = false @git = false - @verbose = ARGV.verbose? + @verbose = Homebrew.args.verbose? @quieter = ARGV.quieter? @debug = ARGV.debug? @installed_as_dependency = false diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 6414640bf4..80113f6b91 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -573,7 +573,9 @@ class Keg begin keg = Keg.for(src) rescue NotAKegError - puts "Won't resolve conflicts for symlink #{dst} as it doesn't resolve into the Cellar" if ARGV.verbose? + if Homebrew.args.verbose? + puts "Won't resolve conflicts for symlink #{dst} as it doesn't resolve into the Cellar" + end return end @@ -584,7 +586,7 @@ class Keg def make_relative_symlink(dst, src, mode) if dst.symlink? && src == dst.resolved_path - puts "Skipping; link already exists: #{dst}" if ARGV.verbose? + puts "Skipping; link already exists: #{dst}" if Homebrew.args.verbose? return end diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index 0ab0085cfa..ca43031ab5 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -127,7 +127,7 @@ class Resource def verify_download_integrity(fn) if fn.file? - ohai "Verifying #{fn.basename} checksum" if ARGV.verbose? + ohai "Verifying #{fn.basename} checksum" if Homebrew.args.verbose? fn.verify_checksum(checksum) end rescue ChecksumMissingError diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb index dab36f0de7..f461629661 100644 --- a/Library/Homebrew/sandbox.rb +++ b/Library/Homebrew/sandbox.rb @@ -127,7 +127,7 @@ class Sandbox end end - if @failed && ARGV.verbose? + if @failed && ENV["HOMEBREW_VERBOSE"].present? ohai "Sandbox log" puts logs $stdout.flush # without it, brew test-bot would fail to catch the log diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index 0cb0d59806..663a8f244b 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -30,7 +30,7 @@ module Homebrew args << "--parallel" end - args += ["--extra-details", "--display-cop-names"] if ARGV.verbose? + args += ["--extra-details", "--display-cop-names"] if Homebrew.args.verbose? if except_cops except_cops.map! { |cop| RuboCop::Cop::Cop.registry.qualified_cop_name(cop.to_s, "") } diff --git a/Library/Homebrew/system_command.rb b/Library/Homebrew/system_command.rb index cebea9c1cd..f21fa78e4c 100644 --- a/Library/Homebrew/system_command.rb +++ b/Library/Homebrew/system_command.rb @@ -222,7 +222,7 @@ class SystemCommand end def warn_plist_garbage(garbage) - return unless ARGV.verbose? + return unless Homebrew.args.verbose? return unless garbage.match?(/\S/) opoo "Received non-XML output from #{Formatter.identifier(command.first)}:" diff --git a/Library/Homebrew/test/rubocops/lines_spec.rb b/Library/Homebrew/test/rubocops/lines_spec.rb index d84b10d889..7b06f52ff9 100644 --- a/Library/Homebrew/test/rubocops/lines_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_spec.rb @@ -604,7 +604,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do desc "foo" url 'https://brew.sh/foo-1.0.tgz' def install - verbose = ARGV.verbose? + verbose = Homebrew.args.verbose? end end RUBY diff --git a/Library/Homebrew/test/system_command_result_spec.rb b/Library/Homebrew/test/system_command_result_spec.rb index 1d53f5e7b6..ccdd3ea6a3 100644 --- a/Library/Homebrew/test/system_command_result_spec.rb +++ b/Library/Homebrew/test/system_command_result_spec.rb @@ -120,7 +120,7 @@ describe SystemCommand::Result do context "when verbose" do before do - allow(ARGV).to receive(:verbose?).and_return(true) + allow(Homebrew.args).to receive(:verbose?).and_return(true) end it "warns about garbage" do @@ -144,7 +144,7 @@ describe SystemCommand::Result do context "when verbose" do before do - allow(ARGV).to receive(:verbose?).and_return(true) + allow(Homebrew.args).to receive(:verbose?).and_return(true) end it "warns about garbage" do diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 4dfc19fe9e..555ed85101 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -35,7 +35,7 @@ module Homebrew end def system(cmd, *args, **options) - if ARGV.verbose? + if Homebrew.args.verbose? puts "#{cmd} #{args * " "}".gsub(RUBY_PATH, "ruby") .gsub($LOAD_PATH.join(File::PATH_SEPARATOR).to_s, "$LOAD_PATH") end @@ -87,7 +87,7 @@ module Kernel end def ohai_title(title) - title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose? + title = Tty.truncate(title) if $stdout.tty? && !Homebrew.args.verbose? Formatter.headline(title, color: :blue) end @@ -104,7 +104,7 @@ module Kernel end def oh1(title, options = {}) - title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose? && options.fetch(:truncate, :auto) == :auto + title = Tty.truncate(title) if $stdout.tty? && !Homebrew.args.verbose? && options.fetch(:truncate, :auto) == :auto puts Formatter.headline(title, color: :green) end @@ -373,7 +373,7 @@ module Kernel end def nostdout - if ARGV.verbose? + if Homebrew.args.verbose? yield else begin diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 5c2f4dbaaf..670b06a828 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -34,7 +34,7 @@ def curl_args(*extra_args, show_output: false, user_agent: :default) unless show_output args << "--fail" - args << "--progress-bar" unless ARGV.verbose? + args << "--progress-bar" unless Homebrew.args.verbose? args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"] args << "--silent" unless $stdout.tty? end