brew/Library/Homebrew/cmd/commands.rb
Martin Afanasjew 21d804eeb8 commands: ensure external commands are executable
For consistency with `brew command` and the logic in `brew.sh` (both use
`which` to find/validate an external command), we need to filter files
that are not executable.

Otherwise `brew commands` and thus bash completion will offer commands
that will produce an error when attempting to use them.

Closes Homebrew/homebrew#44999.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
2015-10-15 19:26:27 +01:00

47 lines
1.3 KiB
Ruby

module Homebrew
def commands
if ARGV.include? "--quiet"
cmds = internal_commands + external_commands
cmds += internal_development_commands if ARGV.homebrew_developer?
cmds += HOMEBREW_INTERNAL_COMMAND_ALIASES.keys if ARGV.include? "--include-aliases"
puts_columns cmds.sort
else
# Find commands in Homebrew/cmd
puts "Built-in commands"
puts_columns internal_commands
# Find commands in Homebrew/dev-cmd
if ARGV.homebrew_developer?
puts
puts "Built-in development commands"
puts_columns internal_development_commands
end
# Find commands in the path
unless (exts = external_commands).empty?
puts
puts "External commands"
puts_columns exts
end
end
end
def internal_commands
with_directory = false
(HOMEBREW_LIBRARY_PATH/"cmd").children(with_directory).map { |f| File.basename(f, ".rb") }
end
def internal_development_commands
with_directory = false
(HOMEBREW_LIBRARY_PATH/"dev-cmd").children(with_directory).map { |f| File.basename(f, ".rb") }
end
def external_commands
paths.flat_map { |p| Dir["#{p}/brew-*"] }.
select { |f| File.executable?(f) }.
map { |f| File.basename(f, ".rb")[5..-1] }.
reject { |f| f =~ /\./ }.
sort
end
end