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