blob: 0dfc6c4512d6691513b6494b1c5cf1578bf98706 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#: * `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.
module Homebrew
module_function
def commands
if ARGV.include? "--quiet"
cmds = internal_commands + external_commands
cmds += internal_developer_commands
cmds += HOMEBREW_INTERNAL_COMMAND_ALIASES.keys if ARGV.include? "--include-aliases"
puts Formatter.columns(cmds.sort)
else
# Find commands in Homebrew/cmd
puts "Built-in commands"
puts Formatter.columns(internal_commands.sort)
# Find commands in Homebrew/dev-cmd
puts
puts "Built-in developer commands"
puts Formatter.columns(internal_developer_commands.sort)
# Find commands in the path
unless (exts = external_commands).empty?
puts
puts "External commands"
puts Formatter.columns(exts)
end
end
end
def internal_commands
find_internal_commands HOMEBREW_LIBRARY_PATH/"cmd"
end
def internal_developer_commands
find_internal_commands HOMEBREW_LIBRARY_PATH/"dev-cmd"
end
def external_commands
paths.each_with_object([]) do |path, cmds|
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)
Pathname.glob(directory/"*")
.select(&:file?)
.map { |f| f.basename.to_s.sub(/\.(?:rb|sh)$/, "") }
end
end
|