| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:  * `commands` [`--quiet` [`--include-aliases`]]: | 
					
						
							|  |  |  | #:    Show a list of built-in and external commands. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--quiet` is passed, list only the names of commands without the header. | 
					
						
							|  |  |  | #:    With `--include-aliases`, the aliases of internal commands will be included. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-14 16:58:26 -07:00
										 |  |  |   def commands | 
					
						
							| 
									
										
										
										
											2015-07-09 19:50:53 +08:00
										 |  |  |     if ARGV.include? "--quiet" | 
					
						
							|  |  |  |       cmds = internal_commands + external_commands | 
					
						
							| 
									
										
										
										
											2016-09-07 20:08:51 +01:00
										 |  |  |       cmds += internal_developer_commands | 
					
						
							| 
									
										
										
										
											2015-07-09 19:50:53 +08:00
										 |  |  |       cmds += HOMEBREW_INTERNAL_COMMAND_ALIASES.keys if ARGV.include? "--include-aliases" | 
					
						
							| 
									
										
										
										
											2016-10-02 20:39:43 +02:00
										 |  |  |       puts Formatter.columns(cmds.sort) | 
					
						
							| 
									
										
										
										
											2015-07-09 19:50:53 +08:00
										 |  |  |     else | 
					
						
							|  |  |  |       # Find commands in Homebrew/cmd | 
					
						
							|  |  |  |       puts "Built-in commands" | 
					
						
							| 
									
										
										
										
											2016-10-02 20:39:43 +02:00
										 |  |  |       puts Formatter.columns(internal_commands) | 
					
						
							| 
									
										
										
										
											2013-09-14 16:58:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-12 19:24:41 +08:00
										 |  |  |       # Find commands in Homebrew/dev-cmd | 
					
						
							| 
									
										
										
										
											2016-09-09 18:10:10 -04:00
										 |  |  |       puts | 
					
						
							|  |  |  |       puts "Built-in developer commands" | 
					
						
							| 
									
										
										
										
											2016-10-02 20:39:43 +02:00
										 |  |  |       puts Formatter.columns(internal_developer_commands) | 
					
						
							| 
									
										
										
										
											2015-09-12 19:24:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-09 19:50:53 +08:00
										 |  |  |       # Find commands in the path | 
					
						
							|  |  |  |       unless (exts = external_commands).empty? | 
					
						
							|  |  |  |         puts | 
					
						
							|  |  |  |         puts "External commands" | 
					
						
							| 
									
										
										
										
											2016-10-02 20:39:43 +02:00
										 |  |  |         puts Formatter.columns(exts) | 
					
						
							| 
									
										
										
										
											2015-07-09 19:50:53 +08:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-09-14 16:58:26 -07:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-07-09 19:50:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def internal_commands | 
					
						
							| 
									
										
										
										
											2016-01-18 00:55:50 +01:00
										 |  |  |     find_internal_commands HOMEBREW_LIBRARY_PATH/"cmd" | 
					
						
							| 
									
										
										
										
											2015-09-12 19:24:41 +08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-07 20:08:51 +01:00
										 |  |  |   def internal_developer_commands | 
					
						
							| 
									
										
										
										
											2016-01-18 00:55:50 +01:00
										 |  |  |     find_internal_commands HOMEBREW_LIBRARY_PATH/"dev-cmd" | 
					
						
							| 
									
										
										
										
											2015-07-09 19:50:53 +08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def external_commands | 
					
						
							| 
									
										
										
										
											2016-09-10 10:24:56 +01:00
										 |  |  |     paths.each_with_object([]) do |path, cmds| | 
					
						
							| 
									
										
										
										
											2016-01-18 00:55:50 +01:00
										 |  |  |       Dir["#{path}/brew-*"].each do |file| | 
					
						
							|  |  |  |         next unless File.executable?(file) | 
					
						
							|  |  |  |         cmd = File.basename(file, ".rb")[5..-1] | 
					
						
							|  |  |  |         cmds << cmd unless cmd.include?(".") | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end.sort | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def find_internal_commands(directory) | 
					
						
							| 
									
										
										
										
											2016-09-10 10:24:56 +01:00
										 |  |  |     directory.children.each_with_object([]) do |f, cmds| | 
					
						
							| 
									
										
										
										
											2016-01-18 00:55:50 +01:00
										 |  |  |       cmds << f.basename.to_s.sub(/\.(?:rb|sh)$/, "") if f.file? | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-07-09 19:50:53 +08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-14 16:58:26 -07:00
										 |  |  | end |