Merge pull request #6857 from GauthamGoli/argv-cleanup-7
ARGV: Replace usages of ARGV.resolved_formulae with Homebrew.args
This commit is contained in:
commit
c0b9167642
@ -25,7 +25,7 @@ module Homebrew
|
||||
if Homebrew.args.named.blank?
|
||||
puts HOMEBREW_CELLAR
|
||||
else
|
||||
puts ARGV.resolved_formulae.map(&:rack)
|
||||
puts Homebrew.args.resolved_formulae.map(&:rack)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -25,7 +25,7 @@ module Homebrew
|
||||
if Homebrew.args.named.blank?
|
||||
puts HOMEBREW_PREFIX
|
||||
else
|
||||
puts ARGV.resolved_formulae.map { |f|
|
||||
puts Homebrew.args.resolved_formulae.map { |f|
|
||||
f.opt_prefix.exist? ? f.opt_prefix : f.installed_prefix
|
||||
}
|
||||
end
|
||||
|
||||
@ -142,10 +142,10 @@ module Homebrew
|
||||
end
|
||||
|
||||
def gist_logs
|
||||
raise FormulaUnspecifiedError if ARGV.resolved_formulae.length != 1
|
||||
raise FormulaUnspecifiedError if Homebrew.args.resolved_formulae.length != 1
|
||||
|
||||
Install.perform_preinstall_checks(all_fatal: true)
|
||||
Install.perform_build_from_source_checks(all_fatal: true)
|
||||
gistify_logs(ARGV.resolved_formulae.first)
|
||||
gistify_logs(Homebrew.args.resolved_formulae.first)
|
||||
end
|
||||
end
|
||||
|
||||
@ -27,7 +27,7 @@ module Homebrew
|
||||
|
||||
raise FormulaUnspecifiedError if Homebrew.args.named.blank?
|
||||
|
||||
ARGV.resolved_formulae.each do |f|
|
||||
Homebrew.args.resolved_formulae.each do |f|
|
||||
if f.oldname
|
||||
unless (rack = HOMEBREW_CELLAR/f.oldname).exist? && !rack.subdirs.empty?
|
||||
raise NoSuchKegError, f.oldname
|
||||
|
||||
@ -33,7 +33,7 @@ module Homebrew
|
||||
ff = if Homebrew.args.named.blank?
|
||||
Formula.installed.sort
|
||||
else
|
||||
ARGV.resolved_formulae.sort
|
||||
Homebrew.args.resolved_formulae.sort
|
||||
end
|
||||
|
||||
ff.each do |f|
|
||||
|
||||
@ -35,10 +35,10 @@ module Homebrew
|
||||
def outdated
|
||||
outdated_args.parse
|
||||
|
||||
formulae = if ARGV.resolved_formulae.empty?
|
||||
formulae = if Homebrew.args.resolved_formulae.blank?
|
||||
Formula.installed
|
||||
else
|
||||
ARGV.resolved_formulae
|
||||
Homebrew.args.resolved_formulae
|
||||
end
|
||||
if args.json
|
||||
raise UsageError, "Invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
|
||||
@ -47,7 +47,7 @@ module Homebrew
|
||||
else
|
||||
outdated = print_outdated(formulae)
|
||||
end
|
||||
Homebrew.failed = !ARGV.resolved_formulae.empty? && !outdated.empty?
|
||||
Homebrew.failed = Homebrew.args.resolved_formulae.present? && !outdated.empty?
|
||||
end
|
||||
|
||||
def print_outdated(formulae)
|
||||
|
||||
@ -23,7 +23,7 @@ module Homebrew
|
||||
|
||||
raise FormulaUnspecifiedError if args.remaining.empty?
|
||||
|
||||
ARGV.resolved_formulae.each do |f|
|
||||
Homebrew.args.resolved_formulae.each do |f|
|
||||
if f.pinned?
|
||||
opoo "#{f.name} already pinned"
|
||||
elsif !f.pinnable?
|
||||
|
||||
@ -25,7 +25,7 @@ module Homebrew
|
||||
|
||||
raise KegUnspecifiedError if args.remaining.empty?
|
||||
|
||||
ARGV.resolved_formulae.each do |f|
|
||||
Homebrew.args.resolved_formulae.each do |f|
|
||||
ohai "Postinstalling #{f}"
|
||||
fi = FormulaInstaller.new(f)
|
||||
fi.post_install
|
||||
|
||||
@ -53,7 +53,7 @@ module Homebrew
|
||||
|
||||
Install.perform_preinstall_checks
|
||||
|
||||
ARGV.resolved_formulae.each do |f|
|
||||
Homebrew.args.resolved_formulae.each do |f|
|
||||
if f.pinned?
|
||||
onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
|
||||
next
|
||||
|
||||
@ -24,7 +24,7 @@ module Homebrew
|
||||
|
||||
raise FormulaUnspecifiedError if args.remaining.empty?
|
||||
|
||||
ARGV.resolved_formulae.each do |f|
|
||||
Homebrew.args.resolved_formulae.each do |f|
|
||||
if f.pinned?
|
||||
f.unpin
|
||||
elsif !f.pinnable?
|
||||
|
||||
@ -68,11 +68,11 @@ module Homebrew
|
||||
|
||||
exit 0 if outdated.empty?
|
||||
else
|
||||
outdated = ARGV.resolved_formulae.select do |f|
|
||||
outdated = Homebrew.args.resolved_formulae.select do |f|
|
||||
f.outdated?(fetch_head: args.fetch_HEAD?)
|
||||
end
|
||||
|
||||
(ARGV.resolved_formulae - outdated).each do |f|
|
||||
(Homebrew.args.resolved_formulae - outdated).each do |f|
|
||||
versions = f.installed_kegs.map(&:version)
|
||||
if versions.empty?
|
||||
ofail "#{f.full_specified_name} not installed"
|
||||
|
||||
@ -83,8 +83,8 @@ module Homebrew
|
||||
ff = Formula
|
||||
files = Tap.map(&:formula_dir)
|
||||
else
|
||||
ff = ARGV.resolved_formulae
|
||||
files = ARGV.resolved_formulae.map(&:path)
|
||||
ff = Homebrew.args.resolved_formulae
|
||||
files = Homebrew.args.resolved_formulae.map(&:path)
|
||||
end
|
||||
|
||||
only_cops = args.only_cops
|
||||
|
||||
@ -89,7 +89,7 @@ module Homebrew
|
||||
raise KegUnspecifiedError if args.remaining.empty?
|
||||
|
||||
ensure_relocation_formulae_installed! unless args.skip_relocation?
|
||||
ARGV.resolved_formulae.each do |f|
|
||||
Homebrew.args.resolved_formulae.each do |f|
|
||||
bottle_formula f
|
||||
end
|
||||
end
|
||||
|
||||
@ -23,6 +23,6 @@ module Homebrew
|
||||
|
||||
raise FormulaUnspecifiedError if Homebrew.args.named.blank?
|
||||
|
||||
ARGV.resolved_formulae.each { |f| puts f.path }
|
||||
Homebrew.args.resolved_formulae.each { |f| puts f.path }
|
||||
end
|
||||
end
|
||||
|
||||
@ -38,7 +38,7 @@ module Homebrew
|
||||
|
||||
require "formula_assertions"
|
||||
|
||||
ARGV.resolved_formulae.each do |f|
|
||||
Homebrew.args.resolved_formulae.each do |f|
|
||||
# Cannot test uninstalled formulae
|
||||
unless f.latest_version_installed?
|
||||
ofail "Testing requires the latest version of #{f.full_name}"
|
||||
|
||||
@ -6,10 +6,6 @@ module HomebrewArgvExtension
|
||||
self - options_only
|
||||
end
|
||||
|
||||
def options_only
|
||||
select { |arg| arg.start_with?("-") }
|
||||
end
|
||||
|
||||
def flags_only
|
||||
select { |arg| arg.start_with?("--") }
|
||||
end
|
||||
@ -26,14 +22,6 @@ module HomebrewArgvExtension
|
||||
end.uniq(&:name)
|
||||
end
|
||||
|
||||
def resolved_formulae
|
||||
require "formula"
|
||||
# TODO: use @instance variable to ||= cache when moving to CLI::Parser
|
||||
(downcased_unique_named - casks).map do |name|
|
||||
Formulary.resolve(name, spec: spec(nil))
|
||||
end.uniq(&:name)
|
||||
end
|
||||
|
||||
def casks
|
||||
# TODO: use @instance variable to ||= cache when moving to CLI::Parser
|
||||
downcased_unique_named.grep HOMEBREW_CASK_TAP_CASK_REGEX
|
||||
@ -118,18 +106,10 @@ module HomebrewArgvExtension
|
||||
formulae.any? { |argv_f| argv_f.full_name == f.full_name }
|
||||
end
|
||||
|
||||
def flag?(flag)
|
||||
options_only.include?(flag) || switch?(flag[2, 1])
|
||||
end
|
||||
|
||||
def force_bottle?
|
||||
include?("--force-bottle")
|
||||
end
|
||||
|
||||
def fetch_head?
|
||||
include? "--fetch-HEAD"
|
||||
end
|
||||
|
||||
def cc
|
||||
value "cc"
|
||||
end
|
||||
@ -153,6 +133,14 @@ module HomebrewArgvExtension
|
||||
|
||||
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
|
||||
|
||||
@ -24,6 +24,7 @@ begin
|
||||
trap("INT", old_trap)
|
||||
|
||||
formula = Homebrew.args.resolved_formulae.first
|
||||
formula.extend(Debrew::Formula) if Homebrew.args.debug?
|
||||
formula.run_post_install
|
||||
rescue Exception => e # rubocop:disable Lint/RescueException
|
||||
error_pipe.puts e.to_json
|
||||
|
||||
@ -9,10 +9,20 @@ require "debrew"
|
||||
require "formula_assertions"
|
||||
require "fcntl"
|
||||
require "socket"
|
||||
require "cli/parser"
|
||||
|
||||
def test_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
switch :force
|
||||
switch :verbose
|
||||
switch :debug
|
||||
end
|
||||
end
|
||||
|
||||
TEST_TIMEOUT_SECONDS = 5 * 60
|
||||
|
||||
begin
|
||||
test_args.parse
|
||||
error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io)
|
||||
error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
|
||||
|
||||
@ -21,9 +31,9 @@ begin
|
||||
|
||||
trap("INT", old_trap)
|
||||
|
||||
formula = ARGV.resolved_formulae.first
|
||||
formula = Homebrew.args.resolved_formulae.first
|
||||
formula.extend(Homebrew::Assertions)
|
||||
formula.extend(Debrew::Formula) if ARGV.debug?
|
||||
formula.extend(Debrew::Formula) if Homebrew.args.debug?
|
||||
|
||||
# tests can also return false to indicate failure
|
||||
Timeout.timeout TEST_TIMEOUT_SECONDS do
|
||||
|
||||
@ -47,7 +47,7 @@ describe HomebrewArgvExtension do
|
||||
let(:argv) { ["--foo", "-vds", "a", "b", "cdefg"] }
|
||||
|
||||
it "returns an array of option arguments" do
|
||||
expect(subject.options_only).to eq ["--foo", "-vds"]
|
||||
expect(subject.send("options_only")).to eq ["--foo", "-vds"]
|
||||
end
|
||||
end
|
||||
|
||||
@ -87,18 +87,18 @@ describe HomebrewArgvExtension do
|
||||
let(:argv) { ["--foo", "-bq", "--bar"] }
|
||||
|
||||
it "returns true if the given string is a flag" do
|
||||
expect(subject.flag?("--foo")).to eq true
|
||||
expect(subject.flag?("--bar")).to eq true
|
||||
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.flag?("--baz")).to eq true
|
||||
expect(subject.flag?("--qux")).to eq true
|
||||
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.flag?("--frotz")).to eq false
|
||||
expect(subject.flag?("--debug")).to eq false
|
||||
expect(subject.send("flag?", "--frotz")).to eq false
|
||||
expect(subject.send("flag?", "--debug")).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user