aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/cli
diff options
context:
space:
mode:
authorMarkus Reiter2017-01-23 17:17:50 +0100
committerGitHub2017-01-23 17:17:50 +0100
commite59ada508727f11464595893783beb914c26f60b (patch)
tree795520e45d29052df65c56503c4a6d2983334ef1 /Library/Homebrew/cask/lib/hbc/cli
parent44596696175bef38f3cde07e4f45285c322996b8 (diff)
parent2076b494a6233630025acd45d9a5766bd6bb785d (diff)
downloadbrew-1.1.8.tar.bz2
Merge pull request #1894 from reitermarkus/appcast-checkpoint1.1.8
Add internal command to calculate appcast checkpoint.
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/cli')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb
new file mode 100644
index 000000000..790e917b2
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb
@@ -0,0 +1,61 @@
+module Hbc
+ class CLI
+ class InternalAppcastCheckpoint < InternalUseBase
+ def self.run(*args)
+ calculate = args.include? "--calculate"
+ cask_tokens = cask_tokens_from(args)
+ raise CaskUnspecifiedError if cask_tokens.empty?
+
+ if cask_tokens.all? { |t| t =~ %r{^https?://} && t !~ /\.rb$/ }
+ appcask_checkpoint_for_url(cask_tokens)
+ else
+ appcask_checkpoint(cask_tokens, calculate)
+ end
+ end
+
+ def self.appcask_checkpoint_for_url(urls)
+ urls.each do |url|
+ appcast = DSL::Appcast.new(url)
+ puts appcast.calculate_checkpoint[:checkpoint]
+ end
+ end
+
+ def self.appcask_checkpoint(cask_tokens, calculate)
+ count = 0
+
+ cask_tokens.each do |cask_token|
+ cask = Hbc.load(cask_token)
+
+ if cask.appcast.nil?
+ opoo "Cask '#{cask}' is missing an `appcast` stanza."
+ else
+ if calculate
+ result = cask.appcast.calculate_checkpoint
+
+ checkpoint = result[:checkpoint]
+ else
+ checkpoint = cask.appcast.checkpoint
+ end
+
+ 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
+ "prints or calculates a given Cask's or URL's appcast checkpoint"
+ end
+
+ def self.needs_init?
+ true
+ end
+ end
+ end
+end