brew/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb

37 lines
926 B
Ruby
Raw Normal View History

2016-09-24 13:52:43 +02:00
module Hbc
class CLI
2017-05-20 19:08:03 +02:00
class InternalDump < AbstractInternalCommand
2017-05-20 02:57:37 +02:00
def initialize(*args)
@cask_tokens = self.class.cask_tokens_from(args)
raise CaskUnspecifiedError if @cask_tokens.empty?
end
def run
retval = dump_casks
2016-09-24 13:52:43 +02:00
# retval is ternary: true/false/nil
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
raise CaskError, "nothing to dump" if retval.nil?
raise CaskError, "dump incomplete" unless retval
end
2016-08-18 22:11:42 +03:00
2017-05-20 02:57:37 +02:00
def dump_casks
2016-09-24 13:52:43 +02:00
count = 0
2017-05-20 02:57:37 +02:00
@cask_tokens.each do |cask_token|
2016-09-24 13:52:43 +02:00
begin
cask = CaskLoader.load(cask_token)
2016-09-24 13:52:43 +02:00
count += 1
cask.dumpcask
rescue StandardError => e
opoo "#{cask_token} was not found or would not load: #{e}"
end
end
2017-05-20 02:57:37 +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
"dump the given Cask in YAML format"
2016-09-24 13:52:43 +02:00
end
end
2016-08-18 22:11:42 +03:00
end
end