| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  | module Hbc | 
					
						
							|  |  |  |   class CLI | 
					
						
							|  |  |  |     class InternalAppcastCheckpoint < InternalUseBase | 
					
						
							|  |  |  |       def self.run(*args) | 
					
						
							| 
									
										
										
										
											2017-01-23 01:03:19 +00:00
										 |  |  |         calculate = args.include? "--calculate" | 
					
						
							| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  |         cask_tokens = cask_tokens_from(args) | 
					
						
							|  |  |  |         raise CaskUnspecifiedError if cask_tokens.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 09:22:51 +01:00
										 |  |  |         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 | 
					
						
							| 
									
										
										
										
											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 |