named_args: Warn when cask with same name exists
This commit is contained in:
parent
4508e7c63b
commit
a7b063efb5
@ -26,6 +26,8 @@ module Homebrew
|
||||
|
||||
downcased_unique_named.each do |name|
|
||||
formulae_and_casks << Formulary.factory(name, spec)
|
||||
|
||||
puts "Treating #{name} as a formula. For the cask, use homebrew/cask/#{name}" if cask_exists_with_ref name
|
||||
rescue FormulaUnavailableError
|
||||
begin
|
||||
formulae_and_casks << Cask::CaskLoader.load(name)
|
||||
@ -51,6 +53,8 @@ module Homebrew
|
||||
|
||||
downcased_unique_named.each do |name|
|
||||
resolved_formulae << Formulary.resolve(name, spec: spec(nil), force_bottle: @force_bottle, flags: @flags)
|
||||
|
||||
puts "Treating #{name} as a formula. For the cask, use homebrew/cask/#{name}" if cask_exists_with_ref name
|
||||
rescue FormulaUnavailableError
|
||||
begin
|
||||
casks << Cask::CaskLoader.load(name)
|
||||
@ -91,6 +95,8 @@ module Homebrew
|
||||
|
||||
downcased_unique_named.each do |name|
|
||||
kegs << resolve_keg(name)
|
||||
|
||||
puts "Treating #{name} as a keg. For the cask, use homebrew/cask/#{name}" if cask_exists_with_ref name
|
||||
rescue NoSuchKegError, FormulaUnavailableError
|
||||
begin
|
||||
casks << Cask::CaskLoader.load(name)
|
||||
@ -163,6 +169,12 @@ module Homebrew
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
def cask_exists_with_ref(ref)
|
||||
Cask::CaskLoader.load ref
|
||||
rescue Cask::CaskUnavailableError
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -39,8 +39,7 @@ describe Homebrew::CLI::NamedArgs do
|
||||
|
||||
describe "#to_formulae" do
|
||||
it "returns formulae" do
|
||||
allow(Formulary).to receive(:loader_for).and_call_original
|
||||
stub_formula_loader foo
|
||||
stub_formula_loader foo, call_original: true
|
||||
stub_formula_loader bar
|
||||
|
||||
expect(described_class.new("foo", "bar").to_formulae).to eq [foo, bar]
|
||||
@ -49,9 +48,8 @@ describe Homebrew::CLI::NamedArgs do
|
||||
|
||||
describe "#to_formulae_and_casks" do
|
||||
it "returns formulae and casks" do
|
||||
allow(Formulary).to receive(:loader_for).and_call_original
|
||||
stub_formula_loader foo
|
||||
stub_cask_loader baz
|
||||
stub_formula_loader foo, call_original: true
|
||||
stub_cask_loader baz, call_original: true
|
||||
|
||||
expect(described_class.new("foo", "baz").to_formulae_and_casks).to eq [foo, baz]
|
||||
end
|
||||
@ -69,7 +67,7 @@ describe Homebrew::CLI::NamedArgs do
|
||||
it "returns resolved formulae, as well as casks" do
|
||||
allow(Formulary).to receive(:resolve).and_call_original
|
||||
allow(Formulary).to receive(:resolve).with("foo", any_args).and_return foo
|
||||
stub_cask_loader baz
|
||||
stub_cask_loader baz, call_original: true
|
||||
|
||||
resolved_formulae, casks = described_class.new("foo", "baz").to_resolved_formulae_to_casks
|
||||
|
||||
@ -101,7 +99,8 @@ describe Homebrew::CLI::NamedArgs do
|
||||
named_args = described_class.new("foo", "baz")
|
||||
allow(named_args).to receive(:resolve_keg).and_call_original
|
||||
allow(named_args).to receive(:resolve_keg).with("foo").and_return foo_keg
|
||||
stub_cask_loader baz
|
||||
|
||||
stub_cask_loader baz, call_original: true
|
||||
|
||||
kegs, casks = named_args.to_kegs_to_casks
|
||||
|
||||
|
||||
@ -5,7 +5,9 @@ require "cask/cask_loader"
|
||||
module Test
|
||||
module Helper
|
||||
module Cask
|
||||
def stub_cask_loader(cask, ref = cask.token)
|
||||
def stub_cask_loader(cask, ref = cask.token, call_original: false)
|
||||
allow(::Cask::CaskLoader).to receive(:for).and_call_original if call_original
|
||||
|
||||
loader = ::Cask::CaskLoader::FromInstanceLoader.new cask
|
||||
allow(::Cask::CaskLoader).to receive(:for).with(ref).and_return(loader)
|
||||
end
|
||||
|
||||
@ -11,7 +11,9 @@ module Test
|
||||
|
||||
# Use a stubbed {Formulary::FormulaLoader} to make a given formula be found
|
||||
# when loading from {Formulary} with `ref`.
|
||||
def stub_formula_loader(formula, ref = formula.full_name)
|
||||
def stub_formula_loader(formula, ref = formula.full_name, call_original: false)
|
||||
allow(Formulary).to receive(:loader_for).and_call_original if call_original
|
||||
|
||||
loader = double(get_formula: formula)
|
||||
allow(Formulary).to receive(:loader_for).with(ref, from: :keg).and_return(loader)
|
||||
allow(Formulary).to receive(:loader_for).with(ref, from: nil).and_return(loader)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user