help: use Commands module.

This commit is contained in:
Mike McQuaid 2016-09-07 20:09:29 +01:00
parent 49dcbee99c
commit ae57057afa

View File

@ -31,12 +31,14 @@ EOS
# NOTE Keep lines less than 80 characters! Wrapping is just not cricket.
# NOTE The reason the string is at the top is so 25 lines is easy to measure!
require "commands"
module Homebrew
def help(cmd = nil, flags = {})
# Resolve command aliases and find file containing the implementation.
if cmd
cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
path = command_path(cmd)
path = Commands.path(cmd)
end
# Display command-specific (or generic) help in response to `UsageError`.
@ -69,18 +71,6 @@ module Homebrew
private
def command_path(cmd)
if File.exist?(HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.sh")
HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.sh"
elsif File.exist?(HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.sh")
HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.sh"
elsif File.exist?(HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.rb")
HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.rb"
elsif File.exist?(HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.rb")
HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.rb"
end
end
def command_help(path)
help_lines = path.read.lines.grep(/^#:/)
if help_lines.empty?