| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   def edit_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       usage_banner <<~EOS | 
					
						
							| 
									
										
										
										
											2019-01-30 21:33:03 +00:00
										 |  |  |         `edit` [<formula>] | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 14:20:27 -04:00
										 |  |  |         Open <formula> in the editor set by `EDITOR` or `HOMEBREW_EDITOR`, or open the | 
					
						
							|  |  |  |         Homebrew repository for editing if no formula is provided. | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2018-04-01 16:47:30 +05:30
										 |  |  |       switch :verbose | 
					
						
							|  |  |  |       switch :debug | 
					
						
							| 
									
										
										
										
											2018-03-25 17:48:22 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def edit | 
					
						
							|  |  |  |     edit_args.parse | 
					
						
							| 
									
										
										
										
											2018-03-24 19:38:34 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     unless (HOMEBREW_REPOSITORY/".git").directory? | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       raise <<~EOS | 
					
						
							| 
									
										
										
										
											2012-08-01 15:56:52 -04:00
										 |  |  |         Changes will be lost! | 
					
						
							| 
									
										
										
										
											2019-04-05 12:24:10 -04:00
										 |  |  |         The first time you `brew update`, all local changes will be lost; you should | 
					
						
							|  |  |  |         thus `brew update` before you `brew edit`! | 
					
						
							| 
									
										
										
										
											2018-06-06 23:34:19 -04:00
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2012-08-01 15:56:52 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-14 14:21:17 +01:00
										 |  |  |     paths = args.formulae_paths.presence | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-14 14:21:17 +01:00
										 |  |  |     # If no brews are listed, open the project root in an editor. | 
					
						
							|  |  |  |     paths ||= [HOMEBREW_REPOSITORY] | 
					
						
							| 
									
										
										
										
											2011-08-24 14:45:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 12:31:29 +01:00
										 |  |  |     exec_editor(*paths) | 
					
						
							| 
									
										
										
										
											2011-08-24 14:45:01 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | end |