| 
									
										
										
										
											2009-10-26 18:16:42 +00:00
										 |  |  | class UsageError <RuntimeError; end | 
					
						
							|  |  |  | class FormulaUnspecifiedError <UsageError; end | 
					
						
							|  |  |  | class KegUnspecifiedError <UsageError; end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  | module HomebrewArgvExtension | 
					
						
							|  |  |  |   def named | 
					
						
							| 
									
										
										
										
											2009-10-26 18:20:18 +00:00
										 |  |  |     @named ||= reject{|arg| arg[0..0] == '-'} | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |   end | 
					
						
							|  |  |  |   def options | 
					
						
							|  |  |  |     select {|arg| arg[0..0] == '-'} | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |   def formulae | 
					
						
							|  |  |  |     require 'formula' | 
					
						
							| 
									
										
										
										
											2009-10-24 18:09:43 +01:00
										 |  |  |     @formulae ||= downcased_unique_named.collect {|name| Formula.factory name} | 
					
						
							| 
									
										
										
										
											2009-10-26 18:16:42 +00:00
										 |  |  |     raise FormulaUnspecifiedError if @formulae.empty? | 
					
						
							| 
									
										
										
										
											2009-10-24 18:09:43 +01:00
										 |  |  |     @formulae | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |   end | 
					
						
							|  |  |  |   def kegs | 
					
						
							|  |  |  |     require 'keg' | 
					
						
							| 
									
										
										
										
											2009-10-24 18:09:43 +01:00
										 |  |  |     @kegs ||= downcased_unique_named.collect do |name| | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |       d=HOMEBREW_CELLAR+name | 
					
						
							| 
									
										
										
										
											2009-11-09 17:42:23 +00:00
										 |  |  |       dirs = d.children.select{ |pn| pn.directory? } rescue [] | 
					
						
							|  |  |  |       raise "#{name} is not installed" if not d.directory? or dirs.length == 0
 | 
					
						
							|  |  |  |       raise "#{name} has multiple installed versions" if dirs.length > 1
 | 
					
						
							|  |  |  |       Keg.new dirs.first | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2009-10-26 18:16:42 +00:00
										 |  |  |     raise KegUnspecifiedError if @kegs.empty? | 
					
						
							| 
									
										
										
										
											2009-10-24 18:09:43 +01:00
										 |  |  |     @kegs | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-09-04 15:22:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |   # self documenting perhaps? | 
					
						
							|  |  |  |   def include? arg | 
					
						
							|  |  |  |     @n=index arg | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |   def next | 
					
						
							| 
									
										
										
										
											2009-10-26 18:20:47 +00:00
										 |  |  |     at @n+1 or raise UsageError | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def force? | 
					
						
							|  |  |  |     flag? '--force' | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |   def verbose? | 
					
						
							| 
									
										
										
										
											2009-10-01 14:44:23 +01:00
										 |  |  |     flag? '--verbose' or ENV['HOMEBREW_VERBOSE'] | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |   end | 
					
						
							|  |  |  |   def debug? | 
					
						
							|  |  |  |     flag? '--debug' or ENV['HOMEBREW_DEBUG'] | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-09-03 17:10:35 +02:00
										 |  |  |   def quieter? | 
					
						
							|  |  |  |     flag? '--quieter' | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-09-10 14:29:41 +01:00
										 |  |  |   def interactive? | 
					
						
							|  |  |  |     flag? '--interactive' | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def flag? flag | 
					
						
							|  |  |  |     options.each do |arg| | 
					
						
							|  |  |  |       return true if arg == flag | 
					
						
							|  |  |  |       next if arg[1..1] == '-' | 
					
						
							|  |  |  |       return true if arg.include? flag[2..2] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     return false | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-09-04 15:22:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-27 17:26:27 +00:00
										 |  |  |   def usage; <<-EOS.undent
 | 
					
						
							|  |  |  |     Usage: brew command [formula] ... | 
					
						
							|  |  |  |     Usage: brew [--prefix] [--cache] [--version|-v] | 
					
						
							|  |  |  |     Usage: brew [--verbose|-v] | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-27 17:26:27 +00:00
										 |  |  |     Principle Commands: | 
					
						
							|  |  |  |       install formula ... [--ignore-dependencies] [--HEAD|-H] | 
					
						
							|  |  |  |       list [--unbrewed] [formula] ... | 
					
						
							|  |  |  |       search [/regex/] [substring] | 
					
						
							|  |  |  |       uninstall formula ... | 
					
						
							|  |  |  |       update | 
					
						
							| 
									
										
										
										
											2010-02-27 16:06:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-27 17:26:27 +00:00
										 |  |  |     Other Commands: | 
					
						
							|  |  |  |       cleanup [formula] | 
					
						
							|  |  |  |       home formula ... | 
					
						
							|  |  |  |       info [formula] [--github] | 
					
						
							|  |  |  |       link formula ... | 
					
						
							|  |  |  |       outdated | 
					
						
							|  |  |  |       prune | 
					
						
							|  |  |  |       unlink formula ... | 
					
						
							| 
									
										
										
										
											2009-09-04 15:22:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-27 17:26:27 +00:00
										 |  |  |     Commands useful when contributing: | 
					
						
							|  |  |  |       create URL | 
					
						
							|  |  |  |       edit [formula] | 
					
						
							|  |  |  |       log formula | 
					
						
							|  |  |  |       install formula [--debug|-d] [--interactive|-i] [--verbose|-v] | 
					
						
							| 
									
										
										
										
											2009-09-24 19:19:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-27 17:26:27 +00:00
										 |  |  |     To visit the Homebrew homepage type: | 
					
						
							|  |  |  |       brew home | 
					
						
							| 
									
										
										
										
											2009-10-26 18:20:18 +00:00
										 |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-09-04 15:22:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-26 18:20:18 +00:00
										 |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-24 18:09:43 +01:00
										 |  |  |   def downcased_unique_named | 
					
						
							| 
									
										
										
										
											2009-10-26 18:20:18 +00:00
										 |  |  |     @downcased_unique_named ||= named.collect{|arg| arg.downcase}.uniq | 
					
						
							| 
									
										
										
										
											2009-08-11 00:27:18 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-08-10 16:27:24 +01:00
										 |  |  | end |