diff options
| author | Mike McQuaid | 2017-11-05 15:37:57 +0000 | 
|---|---|---|
| committer | Mike McQuaid | 2017-11-05 15:37:57 +0000 | 
| commit | 7a68b4a3f96c0cc76f94de2cd72b463b40be0343 (patch) | |
| tree | 3a60bab25001d67966c8bf239b2d7a28f72cd1d3 /Library/Homebrew/cmd/commands.rb | |
| parent | c3006f0f121b44baa7acb5e2a023dfd96e582e7a (diff) | |
| download | brew-7a68b4a3f96c0cc76f94de2cd72b463b40be0343.tar.bz2 | |
Refactor command handling code
Don’t rely on having external commands always present in the PATH in
order to find them. Instead, provide an accessory method to Tap so
they can be added and used when needed.
While we’re here, do some general refactoring and cleanup of the
command code in these places.
Diffstat (limited to 'Library/Homebrew/cmd/commands.rb')
| -rw-r--r-- | Library/Homebrew/cmd/commands.rb | 43 | 
1 files changed, 24 insertions, 19 deletions
| diff --git a/Library/Homebrew/cmd/commands.rb b/Library/Homebrew/cmd/commands.rb index 0dfc6c451..244373482 100644 --- a/Library/Homebrew/cmd/commands.rb +++ b/Library/Homebrew/cmd/commands.rb @@ -9,27 +9,30 @@ module Homebrew    def commands      if ARGV.include? "--quiet" -      cmds = internal_commands + external_commands +      cmds = internal_commands +      cmds += 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 +      return      end + +    # 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) + +    exts = external_commands +    return if exts.empty? + +    # Find commands in the PATH +    puts +    puts "External commands" +    puts Formatter.columns(exts)    end    def internal_commands @@ -41,11 +44,13 @@ module Homebrew    end    def external_commands -    paths.each_with_object([]) do |path, cmds| +    cmd_paths = PATH.new(ENV["PATH"]).append(Tap.cmd_directories) +    cmd_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?(".") +        next if cmd.include?(".") +        cmds << cmd        end      end.sort    end | 
