2016-09-24 13:52:43 +02:00
|
|
|
module Hbc
|
|
|
|
class CLI
|
2017-05-20 19:08:03 +02:00
|
|
|
class InternalStanza < AbstractInternalCommand
|
2016-09-24 13:52:43 +02:00
|
|
|
# Syntax
|
|
|
|
#
|
|
|
|
# brew cask _stanza <stanza_name> [ --table | --yaml | --inspect | --quiet ] [ <cask_token> ... ]
|
|
|
|
#
|
|
|
|
# If no tokens are given, then data for all Casks is returned.
|
|
|
|
#
|
|
|
|
# The pseudo-stanza "artifacts" is available.
|
|
|
|
#
|
|
|
|
# On failure, a blank line is returned on the standard output.
|
|
|
|
#
|
|
|
|
# Examples
|
|
|
|
#
|
|
|
|
# brew cask _stanza appcast --table
|
|
|
|
# brew cask _stanza app --table alfred google-chrome adium voicemac logisim vagrant
|
|
|
|
# brew cask _stanza url --table alfred google-chrome adium voicemac logisim vagrant
|
|
|
|
# brew cask _stanza version --table alfred google-chrome adium voicemac logisim vagrant
|
|
|
|
# brew cask _stanza artifacts --table --inspect alfred google-chrome adium voicemac logisim vagrant
|
|
|
|
# brew cask _stanza artifacts --table --yaml alfred google-chrome adium voicemac logisim vagrant
|
|
|
|
#
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
# TODO: this should be retrievable from Hbc::DSL
|
|
|
|
ARTIFACTS = Set.new [
|
2016-10-14 20:33:16 +02:00
|
|
|
:app,
|
|
|
|
:suite,
|
|
|
|
:artifact,
|
|
|
|
:prefpane,
|
|
|
|
:qlplugin,
|
2016-10-23 17:32:19 +02:00
|
|
|
:dictionary,
|
2016-10-14 20:33:16 +02:00
|
|
|
:font,
|
|
|
|
:service,
|
|
|
|
:colorpicker,
|
|
|
|
:binary,
|
|
|
|
:input_method,
|
|
|
|
:internet_plugin,
|
|
|
|
:audio_unit_plugin,
|
|
|
|
:vst_plugin,
|
|
|
|
:vst3_plugin,
|
|
|
|
:screen_saver,
|
|
|
|
:pkg,
|
|
|
|
:installer,
|
|
|
|
:stage_only,
|
|
|
|
:nested_container,
|
|
|
|
:uninstall,
|
|
|
|
:preflight,
|
2016-12-31 13:39:30 +01:00
|
|
|
:postflight,
|
|
|
|
:uninstall_preflight,
|
2016-10-14 20:33:16 +02:00
|
|
|
:uninstall_postflight,
|
|
|
|
]
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-05-20 03:19:41 +02:00
|
|
|
def initialize(*args)
|
2016-12-31 13:39:30 +01:00
|
|
|
raise ArgumentError, "No stanza given." if args.empty?
|
|
|
|
|
2017-05-20 03:19:41 +02:00
|
|
|
@table = args.include? "--table"
|
|
|
|
@quiet = args.include? "--quiet"
|
|
|
|
@format = :to_yaml if args.include? "--yaml"
|
|
|
|
@format = :inspect if args.include? "--inspect"
|
|
|
|
@cask_tokens = self.class.cask_tokens_from(args)
|
|
|
|
@stanza = @cask_tokens.shift.to_sym
|
|
|
|
@cask_tokens = Hbc.all_tokens if @cask_tokens.empty?
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-05-20 03:19:41 +02:00
|
|
|
def run
|
|
|
|
retval = print_stanzas
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
# retval is ternary: true/false/nil
|
|
|
|
if retval.nil?
|
2017-05-20 03:19:41 +02:00
|
|
|
exit 1 if @quiet
|
2016-09-24 13:52:43 +02:00
|
|
|
raise CaskError, "nothing to print"
|
|
|
|
elsif !retval
|
2017-05-20 03:19:41 +02:00
|
|
|
exit 1 if @quiet
|
2016-09-24 13:52:43 +02:00
|
|
|
raise CaskError, "print incomplete"
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-05-20 03:19:41 +02:00
|
|
|
def print_stanzas
|
2016-09-24 13:52:43 +02:00
|
|
|
count = 0
|
2017-05-20 03:19:41 +02:00
|
|
|
if ARTIFACTS.include?(@stanza)
|
|
|
|
artifact_name = @stanza
|
|
|
|
@stanza = :artifacts
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-05-20 03:19:41 +02:00
|
|
|
@cask_tokens.each do |cask_token|
|
|
|
|
print "#{cask_token}\t" if @table
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
begin
|
2017-03-13 01:09:36 +01:00
|
|
|
cask = CaskLoader.load(cask_token)
|
2016-09-24 13:52:43 +02:00
|
|
|
rescue StandardError
|
2017-05-20 03:19:41 +02:00
|
|
|
opoo "Cask '#{cask_token}' was not found" unless @quiet
|
2016-09-24 13:52:43 +02:00
|
|
|
puts ""
|
|
|
|
next
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-05-20 03:19:41 +02:00
|
|
|
unless cask.respond_to?(@stanza)
|
|
|
|
opoo "no such stanza '#{@stanza}' on Cask '#{cask_token}'" unless @quiet
|
2016-09-24 13:52:43 +02:00
|
|
|
puts ""
|
|
|
|
next
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
begin
|
2017-05-20 03:19:41 +02:00
|
|
|
value = cask.send(@stanza)
|
2016-09-24 13:52:43 +02:00
|
|
|
rescue StandardError
|
2017-05-20 03:19:41 +02:00
|
|
|
opoo "failure calling '#{@stanza}' on Cask '#{cask_token}'" unless @quiet
|
2016-09-24 13:52:43 +02:00
|
|
|
puts ""
|
|
|
|
next
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
if artifact_name && !value.key?(artifact_name)
|
2017-05-20 03:19:41 +02:00
|
|
|
opoo "no such stanza '#{artifact_name}' on Cask '#{cask_token}'" unless @quiet
|
2016-09-24 13:52:43 +02:00
|
|
|
puts ""
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
value = value.fetch(artifact_name).to_a.flatten if artifact_name
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-05-20 03:19:41 +02:00
|
|
|
if @format
|
|
|
|
puts value.send(@format)
|
2016-09-24 13:52:43 +02:00
|
|
|
elsif artifact_name || value.is_a?(Symbol)
|
|
|
|
puts value.inspect
|
|
|
|
else
|
|
|
|
puts value.to_s
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
count += 1
|
|
|
|
end
|
2017-05-20 03:19:41 +02:00
|
|
|
count.zero? ? nil : count == @cask_tokens.length
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def self.help
|
2017-01-23 01:16:07 +00:00
|
|
|
"extract and render a specific stanza for the given Casks"
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|