From c1e673e19a0c02eafb6c24a4ce391b53c2fdbfdc Mon Sep 17 00:00:00 2001 From: Baptiste Fontaine Date: Mon, 18 Jan 2016 00:55:50 +0100 Subject: commands: support .sh commands --- Library/Homebrew/cmd/commands.rb | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'Library/Homebrew/cmd/commands.rb') diff --git a/Library/Homebrew/cmd/commands.rb b/Library/Homebrew/cmd/commands.rb index 6630e7134..88290a43d 100644 --- a/Library/Homebrew/cmd/commands.rb +++ b/Library/Homebrew/cmd/commands.rb @@ -27,18 +27,30 @@ module Homebrew end def internal_commands - (HOMEBREW_LIBRARY_PATH/"cmd").children.select(&:file?).map { |f| f.basename(".rb").to_s } + find_internal_commands HOMEBREW_LIBRARY_PATH/"cmd" end def internal_development_commands - (HOMEBREW_LIBRARY_PATH/"dev-cmd").children.select(&:file?).map { |f| f.basename(".rb").to_s } + find_internal_commands HOMEBREW_LIBRARY_PATH/"dev-cmd" 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 + paths.reduce([]) do |cmds, path| + Dir["#{path}/brew-*"].each do |file| + next unless File.executable?(file) + cmd = File.basename(file, ".rb")[5..-1] + cmds << cmd unless cmd.include?(".") + end + cmds + end.sort + end + + private + + def find_internal_commands(directory) + directory.children.reduce([]) do |cmds, f| + cmds << f.basename.to_s.sub(/\.(?:rb|sh)$/, "") if f.file? + cmds + end end end -- cgit v1.2.3