| 
									
										
										
										
											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-23 14:57:51 +02:00
										 |  |  |         if args.all? { |t| t =~ %r{^https?://} && t !~ /\.rb$/ } | 
					
						
							|  |  |  |           self.class.appcask_checkpoint_for_url(args) | 
					
						
							| 
									
										
										
										
											2017-01-23 09:22:51 +01:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2017-09-12 09:36:07 +02:00
										 |  |  |           self.class.appcask_checkpoint(casks, 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-09-11 08:37:15 +02:00
										 |  |  |       def self.appcask_checkpoint(casks, calculate) | 
					
						
							|  |  |  |         casks.each do |cask| | 
					
						
							| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  |           if cask.appcast.nil? | 
					
						
							|  |  |  |             opoo "Cask '#{cask}' is missing an `appcast` stanza." | 
					
						
							|  |  |  |           else | 
					
						
							| 
									
										
										
										
											2017-09-11 08:37:15 +02:00
										 |  |  |             checkpoint = if calculate | 
					
						
							| 
									
										
										
										
											2017-01-23 01:03:19 +00:00
										 |  |  |               result = cask.appcast.calculate_checkpoint | 
					
						
							| 
									
										
										
										
											2017-09-11 08:37:15 +02:00
										 |  |  |               result[:checkpoint] | 
					
						
							| 
									
										
										
										
											2017-01-23 01:03:19 +00:00
										 |  |  |             else | 
					
						
							| 
									
										
										
										
											2017-09-11 08:37:15 +02:00
										 |  |  |               cask.appcast.checkpoint | 
					
						
							| 
									
										
										
										
											2017-01-23 01:03:19 +00:00
										 |  |  |             end | 
					
						
							| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-11 08:37:15 +02:00
										 |  |  |             if calculate && checkpoint.nil? | 
					
						
							| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  |               onoe "Could not retrieve `appcast` checkpoint for cask '#{cask}': #{result[:command_result].stderr}" | 
					
						
							| 
									
										
										
										
											2017-09-11 08:37:15 +02:00
										 |  |  |             elsif casks.count > 1
 | 
					
						
							|  |  |  |               puts "#{checkpoint}  #{cask}" | 
					
						
							| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  |             else | 
					
						
							| 
									
										
										
										
											2017-09-11 08:37:15 +02:00
										 |  |  |               puts checkpoint | 
					
						
							| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  |             end | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       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 |