aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
diff options
context:
space:
mode:
authorMarkus Reiter2017-11-20 21:41:48 +0100
committerGitHub2017-11-20 21:41:48 +0100
commit236b0172306a6f4b233d374fcc20adce5c3e3261 (patch)
treef9bc411e42ba88586abbc57ec0479ad0914b4264 /Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
parentc458c902369d039acb818e9f71393084a33df491 (diff)
parent17e001bd306e5cedd207475985052205b6ddeac6 (diff)
downloadbrew-1.3.8.tar.bz2
Merge pull request #3258 from Git-Jiro/improve_internal_stanza_command1.3.8
improve 'brew cask _stanza' by checking for known stanzas
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb37
1 files changed, 13 insertions, 24 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
index c04619798..bafaadc24 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
@@ -43,6 +43,13 @@ module Hbc
@stanza = args.shift.to_sym
@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
def run
@@ -54,12 +61,6 @@ module Hbc
casks(alternative: -> { Hbc.all }).each do |cask|
print "#{cask}\t" if table?
- unless cask.respond_to?(stanza)
- opoo "no such stanza '#{stanza}' on Cask '#{cask}'" unless quiet?
- puts ""
- next
- end
-
begin
value = cask.send(stanza)
rescue StandardError
@@ -68,26 +69,14 @@ module Hbc
next
end
- if artifact_name && !value.key?(artifact_name)
- opoo "no such stanza '#{artifact_name}' on Cask '#{cask}'" unless quiet?
- puts ""
- next
- end
-
if stanza == :artifacts
- value = Hash[
- value.map do |k, v|
- 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 = Hash[value.map { |v| [v.class.dsl_key, v.to_s] }]
+ value = value[artifact_name] if artifact_name
+ end
- value = value.fetch(artifact_name) if artifact_name
+ if value.nil? || (value.respond_to?(:to_a) && value.to_a.empty?)
+ stanza_name = artifact_name ? artifact_name : stanza
+ raise CaskError, "no such stanza '#{stanza_name}' on Cask '#{cask}'"
end
if format