2017-01-22 04:28:33 +01:00
|
|
|
module Hbc
|
|
|
|
class CLI
|
2017-05-20 19:08:03 +02:00
|
|
|
class InternalAppcastCheckpoint < AbstractInternalCommand
|
2017-05-21 00:15:56 +02:00
|
|
|
option "--calculate", :calculate, false
|
|
|
|
|
|
|
|
def initialize(*)
|
|
|
|
super
|
|
|
|
raise CaskUnspecifiedError if args.empty?
|
2017-05-20 02:43:45 +02:00
|
|
|
end
|
2017-01-22 04:28:33 +01:00
|
|
|
|
2017-05-20 02:43:45 +02:00
|
|
|
def run
|
2017-05-21 00:15:56 +02:00
|
|
|
if cask_tokens.all? { |t| t =~ %r{^https?://} && t !~ /\.rb$/ }
|
2017-05-20 02:43:45 +02:00
|
|
|
self.class.appcask_checkpoint_for_url(cask_tokens)
|
2017-01-23 09:22:51 +01:00
|
|
|
else
|
2017-05-21 00:15:56 +02:00
|
|
|
self.class.appcask_checkpoint(cask_tokens, calculate?)
|
2017-01-23 09:22:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.appcask_checkpoint_for_url(urls)
|
|
|
|
urls.each do |url|
|
|
|
|
appcast = DSL::Appcast.new(url)
|
|
|
|
puts appcast.calculate_checkpoint[:checkpoint]
|
|
|
|
end
|
2017-01-22 04:28:33 +01:00
|
|
|
end
|
|
|
|
|
2017-01-23 01:03:19 +00:00
|
|
|
def self.appcask_checkpoint(cask_tokens, calculate)
|
2017-01-22 04:28:33 +01:00
|
|
|
count = 0
|
|
|
|
|
|
|
|
cask_tokens.each do |cask_token|
|
2017-03-13 01:09:36 +01:00
|
|
|
cask = CaskLoader.load(cask_token)
|
2017-01-22 04:28:33 +01:00
|
|
|
|
|
|
|
if cask.appcast.nil?
|
|
|
|
opoo "Cask '#{cask}' is missing an `appcast` stanza."
|
|
|
|
else
|
2017-01-23 01:03:19 +00:00
|
|
|
if calculate
|
|
|
|
result = cask.appcast.calculate_checkpoint
|
2017-01-22 04:28:33 +01:00
|
|
|
|
2017-01-23 01:03:19 +00:00
|
|
|
checkpoint = result[:checkpoint]
|
|
|
|
else
|
|
|
|
checkpoint = cask.appcast.checkpoint
|
|
|
|
end
|
2017-01-22 04:28:33 +01:00
|
|
|
|
|
|
|
if checkpoint.nil?
|
|
|
|
onoe "Could not retrieve `appcast` checkpoint for cask '#{cask}': #{result[:command_result].stderr}"
|
|
|
|
else
|
|
|
|
puts cask_tokens.count > 1 ? "#{checkpoint} #{cask}": checkpoint
|
|
|
|
count += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
count == cask_tokens.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.help
|
2017-01-23 16:23:01 +01:00
|
|
|
"prints or calculates a given Cask's or URL's appcast checkpoint"
|
2017-01-22 04:28:33 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.needs_init?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|