| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  | module Cask | 
					
						
							| 
									
										
										
										
											2018-09-04 08:45:48 +01:00
										 |  |  |   class Cmd | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:07 +02:00
										 |  |  |     # Implementation of the `brew cask edit` command. | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  |     # @api private | 
					
						
							| 
									
										
										
										
											2017-05-20 19:08:03 +02:00
										 |  |  |     class Edit < AbstractCommand | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       sig { override.returns(T.nilable(T.any(Integer, Symbol))) } | 
					
						
							| 
									
										
										
										
											2020-08-01 02:30:46 +02:00
										 |  |  |       def self.min_named | 
					
						
							|  |  |  |         :cask | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       sig { override.returns(T.nilable(Integer)) } | 
					
						
							| 
									
										
										
										
											2020-08-01 02:30:46 +02:00
										 |  |  |       def self.max_named | 
					
						
							|  |  |  |         1
 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       sig { returns(String) } | 
					
						
							| 
									
										
										
										
											2020-08-01 02:30:46 +02:00
										 |  |  |       def self.description | 
					
						
							|  |  |  |         "Open the given <cask> for editing." | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-21 00:15:56 +02:00
										 |  |  |       def initialize(*) | 
					
						
							|  |  |  |         super | 
					
						
							| 
									
										
										
										
											2020-08-01 02:30:46 +02:00
										 |  |  |       rescue Homebrew::CLI::MaxNamedArgumentsError | 
					
						
							|  |  |  |         raise UsageError, "Only one cask can be edited at a time." | 
					
						
							| 
									
										
										
										
											2017-05-21 00:15:56 +02:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       sig { void } | 
					
						
							| 
									
										
										
										
											2017-05-19 22:01:50 +02:00
										 |  |  |       def run | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         exec_editor cask_path | 
					
						
							| 
									
										
										
										
											2017-09-11 08:37:15 +02:00
										 |  |  |       rescue CaskUnavailableError => e | 
					
						
							| 
									
										
										
										
											2019-04-20 14:07:29 +09:00
										 |  |  |         reason = e.reason.empty? ? +"" : +"#{e.reason} " | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |         reason.concat( | 
					
						
							|  |  |  |           "Run #{Formatter.identifier("brew create --cask --set-name #{e.token} <url>")} to create a new Cask.", | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2019-04-20 14:07:29 +09:00
										 |  |  |         raise e.class.new(e.token, reason.freeze) | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 22:04:20 +02:00
										 |  |  |       def cask_path | 
					
						
							|  |  |  |         casks.first.sourcefile_path | 
					
						
							| 
									
										
										
										
											2019-04-20 23:56:55 +02:00
										 |  |  |       rescue CaskInvalidError, CaskUnreadableError, MethodDeprecatedError | 
					
						
							| 
									
										
										
										
											2017-10-15 22:04:20 +02:00
										 |  |  |         path = CaskLoader.path(args.first) | 
					
						
							|  |  |  |         return path if path.file? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 22:04:20 +02:00
										 |  |  |         raise | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |