Merge pull request #3258 from Git-Jiro/improve_internal_stanza_command
improve 'brew cask _stanza' by checking for known stanzas
This commit is contained in:
commit
236b017230
@ -43,6 +43,13 @@ module Hbc
|
|||||||
@stanza = args.shift.to_sym
|
@stanza = args.shift.to_sym
|
||||||
|
|
||||||
@format = :to_yaml if yaml?
|
@format = :to_yaml if yaml?
|
||||||
|
|
||||||
|
return if DSL::DSL_METHODS.include?(stanza)
|
||||||
|
raise ArgumentError,
|
||||||
|
<<~EOS
|
||||||
|
Unknown/unsupported stanza: '#{stanza}'
|
||||||
|
Check Cask reference for supported stanzas.
|
||||||
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
@ -54,12 +61,6 @@ module Hbc
|
|||||||
casks(alternative: -> { Hbc.all }).each do |cask|
|
casks(alternative: -> { Hbc.all }).each do |cask|
|
||||||
print "#{cask}\t" if table?
|
print "#{cask}\t" if table?
|
||||||
|
|
||||||
unless cask.respond_to?(stanza)
|
|
||||||
opoo "no such stanza '#{stanza}' on Cask '#{cask}'" unless quiet?
|
|
||||||
puts ""
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
value = cask.send(stanza)
|
value = cask.send(stanza)
|
||||||
rescue StandardError
|
rescue StandardError
|
||||||
@ -68,26 +69,14 @@ module Hbc
|
|||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
if artifact_name && !value.key?(artifact_name)
|
if stanza == :artifacts
|
||||||
opoo "no such stanza '#{artifact_name}' on Cask '#{cask}'" unless quiet?
|
value = Hash[value.map { |v| [v.class.dsl_key, v.to_s] }]
|
||||||
puts ""
|
value = value[artifact_name] if artifact_name
|
||||||
next
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if stanza == :artifacts
|
if value.nil? || (value.respond_to?(:to_a) && value.to_a.empty?)
|
||||||
value = Hash[
|
stanza_name = artifact_name ? artifact_name : stanza
|
||||||
value.map do |k, v|
|
raise CaskError, "no such stanza '#{stanza_name}' on Cask '#{cask}'"
|
||||||
v = v.map do |a|
|
|
||||||
next a.to_a if a.respond_to?(:to_a)
|
|
||||||
next a.to_h if a.respond_to?(:to_h)
|
|
||||||
a
|
|
||||||
end
|
|
||||||
|
|
||||||
[k, v]
|
|
||||||
end
|
|
||||||
]
|
|
||||||
|
|
||||||
value = value.fetch(artifact_name) if artifact_name
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if format
|
if format
|
||||||
|
|||||||
42
Library/Homebrew/test/cask/cli/internal_stanza_spec.rb
Normal file
42
Library/Homebrew/test/cask/cli/internal_stanza_spec.rb
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
describe Hbc::CLI::InternalStanza, :cask do
|
||||||
|
it "shows stanza of the Specified Cask" do
|
||||||
|
command = described_class.new("gpg", "with-gpg")
|
||||||
|
expect {
|
||||||
|
command.run
|
||||||
|
}.to output("http://example.com/gpg-signature.asc\n").to_stdout
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises an exception when stanza is unknown/unsupported" do
|
||||||
|
expect {
|
||||||
|
described_class.new("this_stanza_does_not_exist", "with-gpg")
|
||||||
|
}.to raise_error(%r{Unknown/unsupported stanza})
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises an exception when normal stanza is not present on cask" do
|
||||||
|
command = described_class.new("caveats", "with-gpg")
|
||||||
|
expect {
|
||||||
|
command.run
|
||||||
|
}.to raise_error(/no such stanza/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises an exception when artifact stanza is not present on cask" do
|
||||||
|
command = described_class.new("zap", "with-gpg")
|
||||||
|
expect {
|
||||||
|
command.run
|
||||||
|
}.to raise_error(/no such stanza/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises an exception when 'depends_on' stanza is not present on cask" do
|
||||||
|
command = described_class.new("depends_on", "with-gpg")
|
||||||
|
expect {
|
||||||
|
command.run
|
||||||
|
}.to raise_error(/no such stanza/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "shows all artifact stanzas when using 'artifacts' keyword" do
|
||||||
|
command = described_class.new("artifacts", "with-gpg")
|
||||||
|
expect {
|
||||||
|
command.run
|
||||||
|
}.to output(/Caffeine\.app/).to_stdout
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user