mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
parent
e1f3c8d2b3
commit
bc27e38f18
@ -139,8 +139,8 @@ rescue UsageError => e
|
|||||||
require "help"
|
require "help"
|
||||||
Homebrew::Help.help cmd, usage_error: e.message
|
Homebrew::Help.help cmd, usage_error: e.message
|
||||||
rescue SystemExit => e
|
rescue SystemExit => e
|
||||||
onoe "Kernel.exit" if ARGV.debug? && !e.success?
|
onoe "Kernel.exit" if Homebrew.args.debug? && !e.success?
|
||||||
$stderr.puts e.backtrace if ARGV.debug?
|
$stderr.puts e.backtrace if Homebrew.args.debug?
|
||||||
raise
|
raise
|
||||||
rescue Interrupt
|
rescue Interrupt
|
||||||
$stderr.puts # seemingly a newline is typical
|
$stderr.puts # seemingly a newline is typical
|
||||||
@ -156,7 +156,7 @@ rescue RuntimeError, SystemCallError => e
|
|||||||
raise if e.message.empty?
|
raise if e.message.empty?
|
||||||
|
|
||||||
onoe e
|
onoe e
|
||||||
$stderr.puts e.backtrace if ARGV.debug?
|
$stderr.puts e.backtrace if Homebrew.args.debug?
|
||||||
|
|
||||||
output_unsupported_error if Homebrew.args.HEAD?
|
output_unsupported_error if Homebrew.args.HEAD?
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ rescue MethodDeprecatedError => e
|
|||||||
$stderr.puts "If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):"
|
$stderr.puts "If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):"
|
||||||
$stderr.puts " #{Formatter.url(e.issues_url)}"
|
$stderr.puts " #{Formatter.url(e.issues_url)}"
|
||||||
end
|
end
|
||||||
$stderr.puts e.backtrace if ARGV.debug?
|
$stderr.puts e.backtrace if Homebrew.args.debug?
|
||||||
exit 1
|
exit 1
|
||||||
rescue Exception => e # rubocop:disable Lint/RescueException
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
||||||
onoe e
|
onoe e
|
||||||
|
@ -116,7 +116,7 @@ class Build
|
|||||||
}
|
}
|
||||||
|
|
||||||
with_env(new_env) do
|
with_env(new_env) do
|
||||||
formula.extend(Debrew::Formula) if ARGV.debug?
|
formula.extend(Debrew::Formula) if Homebrew.args.debug?
|
||||||
|
|
||||||
formula.update_head_version
|
formula.update_head_version
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ module Cask
|
|||||||
end
|
end
|
||||||
rescue CaskError, MethodDeprecatedError, ArgumentError, OptionParser::InvalidOption => e
|
rescue CaskError, MethodDeprecatedError, ArgumentError, OptionParser::InvalidOption => e
|
||||||
onoe e.message
|
onoe e.message
|
||||||
$stderr.puts e.backtrace if ARGV.debug?
|
$stderr.puts e.backtrace if Homebrew.args.debug?
|
||||||
exit 1
|
exit 1
|
||||||
rescue StandardError, ScriptError, NoMemoryError => e
|
rescue StandardError, ScriptError, NoMemoryError => e
|
||||||
onoe e.message
|
onoe e.message
|
||||||
|
@ -109,7 +109,7 @@ class Cleaner
|
|||||||
else
|
else
|
||||||
0444
|
0444
|
||||||
end
|
end
|
||||||
if ARGV.debug?
|
if Homebrew.args.debug?
|
||||||
old_perms = path.stat.mode & 0777
|
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
|
odebug "Fixing #{path} permissions from #{old_perms.to_s(8)} to #{perms.to_s(8)}" if perms != old_perms
|
||||||
end
|
end
|
||||||
|
@ -6,50 +6,4 @@ module HomebrewArgvExtension
|
|||||||
flag_with_value = find { |arg| arg.start_with?(arg_prefix) }
|
flag_with_value = find { |arg| arg.start_with?(arg_prefix) }
|
||||||
flag_with_value&.delete_prefix(arg_prefix)
|
flag_with_value&.delete_prefix(arg_prefix)
|
||||||
end
|
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
|
end
|
||||||
|
@ -1172,7 +1172,7 @@ class Formula
|
|||||||
begin
|
begin
|
||||||
yield self, staging
|
yield self, staging
|
||||||
rescue
|
rescue
|
||||||
staging.retain! if Homebrew.args.interactive? || ARGV.debug?
|
staging.retain! if Homebrew.args.interactive? || Homebrew.args.debug?
|
||||||
raise
|
raise
|
||||||
ensure
|
ensure
|
||||||
cp Dir["config.log", "CMakeCache.txt"], logs
|
cp Dir["config.log", "CMakeCache.txt"], logs
|
||||||
@ -1822,7 +1822,7 @@ class Formula
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception # rubocop:disable Lint/RescueException
|
rescue Exception # rubocop:disable Lint/RescueException
|
||||||
staging.retain! if ARGV.debug?
|
staging.retain! if Homebrew.args.debug?
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,7 +59,7 @@ class FormulaInstaller
|
|||||||
@git = false
|
@git = false
|
||||||
@verbose = Homebrew.args.verbose?
|
@verbose = Homebrew.args.verbose?
|
||||||
@quiet = Homebrew.args.quiet?
|
@quiet = Homebrew.args.quiet?
|
||||||
@debug = ARGV.debug?
|
@debug = Homebrew.args.debug?
|
||||||
@installed_as_dependency = false
|
@installed_as_dependency = false
|
||||||
@installed_on_request = true
|
@installed_on_request = true
|
||||||
@options = Options.new
|
@options = Options.new
|
||||||
|
@ -44,7 +44,7 @@ class FormulaVersions
|
|||||||
rescue *IGNORED_EXCEPTIONS => e
|
rescue *IGNORED_EXCEPTIONS => e
|
||||||
# We rescue these so that we can skip bad versions and
|
# We rescue these so that we can skip bad versions and
|
||||||
# continue walking the history
|
# 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
|
rescue FormulaUnavailableError
|
||||||
nil
|
nil
|
||||||
ensure
|
ensure
|
||||||
|
@ -130,7 +130,7 @@ module Formulary
|
|||||||
private
|
private
|
||||||
|
|
||||||
def load_file
|
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?
|
raise FormulaUnavailableError, name unless path.file?
|
||||||
|
|
||||||
Formulary.load_formula_from_path(name, path)
|
Formulary.load_formula_from_path(name, path)
|
||||||
@ -302,7 +302,7 @@ module Formulary
|
|||||||
end
|
end
|
||||||
|
|
||||||
def klass
|
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)}"
|
namespace = "FormulaNamespace#{Digest::MD5.hexdigest(contents)}"
|
||||||
Formulary.load_formula(name, path, contents, namespace)
|
Formulary.load_formula(name, path, contents, namespace)
|
||||||
end
|
end
|
||||||
|
@ -209,7 +209,7 @@ class Migrator
|
|||||||
rescue Exception => e # rubocop:disable Lint/RescueException
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
||||||
onoe "Error occurred while migrating."
|
onoe "Error occurred while migrating."
|
||||||
puts e
|
puts e
|
||||||
puts e.backtrace if ARGV.debug?
|
puts e.backtrace if Homebrew.args.debug?
|
||||||
puts "Backing up..."
|
puts "Backing up..."
|
||||||
ignore_interrupts { backup_oldname }
|
ignore_interrupts { backup_oldname }
|
||||||
ensure
|
ensure
|
||||||
@ -318,7 +318,7 @@ class Migrator
|
|||||||
rescue Exception => e # rubocop:disable Lint/RescueException
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
||||||
onoe "An unexpected error occurred during linking"
|
onoe "An unexpected error occurred during linking"
|
||||||
puts e
|
puts e
|
||||||
puts e.backtrace if ARGV.debug?
|
puts e.backtrace if Homebrew.args.debug?
|
||||||
ignore_interrupts { new_keg.unlink }
|
ignore_interrupts { new_keg.unlink }
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ class Keg
|
|||||||
return if file.dylib_id == id
|
return if file.dylib_id == id
|
||||||
|
|
||||||
@require_relocation = true
|
@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)
|
MachO::Tools.change_dylib_id(file, id, strict: false)
|
||||||
rescue MachO::MachOError
|
rescue MachO::MachOError
|
||||||
onoe <<~EOS
|
onoe <<~EOS
|
||||||
@ -20,7 +20,7 @@ class Keg
|
|||||||
return if old == new
|
return if old == new
|
||||||
|
|
||||||
@require_relocation = true
|
@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)
|
MachO::Tools.change_install_name(file, old, new, strict: false)
|
||||||
rescue MachO::MachOError
|
rescue MachO::MachOError
|
||||||
onoe <<~EOS
|
onoe <<~EOS
|
||||||
|
@ -77,7 +77,7 @@ module Homebrew
|
|||||||
|
|
||||||
case output_type
|
case output_type
|
||||||
when :print
|
when :print
|
||||||
args << "--debug" if ARGV.debug?
|
args << "--debug" if Homebrew.args.debug?
|
||||||
args << "--display-cop-names" if Homebrew.args.display_cop_names?
|
args << "--display-cop-names" if Homebrew.args.display_cop_names?
|
||||||
args << "--format" << "simple" if files
|
args << "--format" << "simple" if files
|
||||||
system(cache_env, "rubocop", *args)
|
system(cache_env, "rubocop", *args)
|
||||||
|
@ -34,7 +34,7 @@ class SystemCommand
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run!
|
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 = []
|
@output = []
|
||||||
|
|
||||||
|
@ -7,73 +7,6 @@ describe HomebrewArgvExtension do
|
|||||||
|
|
||||||
let(:argv) { ["mxcl"] }
|
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
|
describe "#value" do
|
||||||
let(:argv) { ["--foo=", "--bar=ab"] }
|
let(:argv) { ["--foo=", "--bar=ab"] }
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ module Kernel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def odebug(title, *sput)
|
def odebug(title, *sput)
|
||||||
return unless ARGV.debug?
|
return unless Homebrew.args.debug?
|
||||||
|
|
||||||
puts Formatter.headline(title, color: :magenta)
|
puts Formatter.headline(title, color: :magenta)
|
||||||
puts sput unless sput.empty?
|
puts sput unless sput.empty?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user