mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #8636 from reitermarkus/brew-style-casks
Support passing casks in `brew style`.
This commit is contained in:
commit
c942aafc4c
@ -74,8 +74,33 @@ module Homebrew
|
||||
end
|
||||
|
||||
def to_formulae_paths
|
||||
@to_formulae_paths ||= (downcased_unique_named - homebrew_tap_cask_names).map do |name|
|
||||
Formulary.path(name)
|
||||
to_paths(only: :formulae)
|
||||
end
|
||||
|
||||
# Keep existing paths and try to convert others to tap, formula or cask paths.
|
||||
# If a cask and formula with the same name exist, includes both their paths
|
||||
# unless `only` is specified.
|
||||
def to_paths(only: nil)
|
||||
@to_paths ||= {}
|
||||
@to_paths[only] ||= downcased_unique_named.flat_map do |name|
|
||||
if File.exist?(name)
|
||||
Pathname(name)
|
||||
elsif name.count("/") == 1
|
||||
Tap.fetch(name).path
|
||||
else
|
||||
next Formulary.path(name) if only == :formulae
|
||||
next Cask::CaskLoader.path(name) if only == :casks
|
||||
|
||||
formula_path = Formulary.path(name)
|
||||
cask_path = Cask::CaskLoader.path(name)
|
||||
|
||||
paths = []
|
||||
|
||||
paths << formula_path if formula_path.exist?
|
||||
paths << cask_path if cask_path.exist?
|
||||
|
||||
paths.empty? ? name : paths
|
||||
end
|
||||
end.uniq.freeze
|
||||
end
|
||||
|
||||
|
@ -39,12 +39,8 @@ module Homebrew
|
||||
|
||||
target = if args.no_named?
|
||||
nil
|
||||
elsif args.named.any? { |file| File.exist? file }
|
||||
args.named
|
||||
elsif args.named.any? { |tap| tap.count("/") == 1 }
|
||||
args.named.map { |tap| Tap.fetch(tap).path }
|
||||
else
|
||||
args.named.to_formulae_paths
|
||||
args.named.to_paths
|
||||
end
|
||||
|
||||
only_cops = args.only_cops
|
||||
|
@ -133,10 +133,9 @@ module Homebrew
|
||||
when :print
|
||||
args << "--debug" if debug
|
||||
|
||||
if ENV["CI"]
|
||||
# Don't show the default formatter's progress dots on CI.
|
||||
args << "--format" << "clang"
|
||||
end
|
||||
# Don't show the default formatter's progress dots
|
||||
# on CI or if only checking a single file.
|
||||
args << "--format" << "clang" if ENV["CI"] || files.count { |f| !f.directory? } == 1
|
||||
|
||||
args << "--color" if Tty.color?
|
||||
|
||||
|
@ -120,4 +120,45 @@ describe Homebrew::CLI::NamedArgs do
|
||||
expect(described_class.new("foo").homebrew_tap_cask_names).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe "#to_paths" do
|
||||
let(:existing_path) { mktmpdir }
|
||||
let(:formula_path) { Pathname("/path/to/foo.rb") }
|
||||
let(:cask_path) { Pathname("/path/to/baz.rb") }
|
||||
|
||||
before do
|
||||
allow(formula_path).to receive(:exist?).and_return(true)
|
||||
allow(cask_path).to receive(:exist?).and_return(true)
|
||||
|
||||
allow(Formulary).to receive(:path).and_call_original
|
||||
allow(Cask::CaskLoader).to receive(:path).and_call_original
|
||||
end
|
||||
|
||||
it "returns taps, cask formula and existing paths" do
|
||||
expect(Formulary).to receive(:path).with("foo").and_return(formula_path)
|
||||
expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_path)
|
||||
|
||||
expect(described_class.new("homebrew/core", "foo", "baz", existing_path.to_s).to_paths)
|
||||
.to eq [Tap.fetch("homebrew/core").path, formula_path, cask_path, existing_path]
|
||||
end
|
||||
|
||||
it "returns both cask and formula paths if they exist" do
|
||||
expect(Formulary).to receive(:path).with("foo").and_return(formula_path)
|
||||
expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_path)
|
||||
|
||||
expect(described_class.new("foo", "baz").to_paths).to eq [formula_path, cask_path]
|
||||
end
|
||||
|
||||
it "returns only formulae when `only: :formulae` is specified" do
|
||||
expect(Formulary).to receive(:path).with("foo").and_return(formula_path)
|
||||
|
||||
expect(described_class.new("foo", "baz").to_paths(only: :formulae)).to eq [formula_path, Formulary.path("baz")]
|
||||
end
|
||||
|
||||
it "returns only casks when `only: :casks` is specified" do
|
||||
expect(Cask::CaskLoader).to receive(:path).with("foo").and_return(cask_path)
|
||||
|
||||
expect(described_class.new("foo", "baz").to_paths(only: :casks)).to eq [cask_path, Cask::CaskLoader.path("baz")]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user