aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/cmd/help.rb28
-rw-r--r--Library/brew.rb26
2 files changed, 29 insertions, 25 deletions
diff --git a/Library/Homebrew/cmd/help.rb b/Library/Homebrew/cmd/help.rb
index 77b562745..d82ed8c20 100644
--- a/Library/Homebrew/cmd/help.rb
+++ b/Library/Homebrew/cmd/help.rb
@@ -32,14 +32,38 @@ EOS
# NOTE The reason the string is at the top is so 25 lines is easy to measure!
module Homebrew
- def help
- puts HOMEBREW_HELP
+ def help(cmd = nil, empty_argv = false)
+ # Handle `brew` (no arguments).
+ if empty_argv
+ $stderr.puts HOMEBREW_HELP
+ exit 1
+ end
+
+ # Handle `brew (-h|--help|--usage|-?|help)` (no other arguments).
+ if cmd.nil?
+ puts HOMEBREW_HELP
+ exit 0
+ end
+
+ # Get help text and if `nil` (external commands), resume in `brew.rb`.
+ help_text = help_for_command(cmd)
+ return if help_text.nil?
+
+ # Display help for internal command (or generic help if undocumented).
+ if help_text.empty?
+ opoo "No help available for '#{cmd}' command."
+ help_text = HOMEBREW_HELP
+ end
+ puts help_text
+ exit 0
end
def help_s
HOMEBREW_HELP
end
+ private
+
def help_for_command(cmd)
cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
cmd_path = if File.exist?(HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.sh")
diff --git a/Library/brew.rb b/Library/brew.rb
index a70c5755e..7207e22b6 100644
--- a/Library/brew.rb
+++ b/Library/brew.rb
@@ -68,29 +68,9 @@ begin
#
# It should never affect external commands so they can handle usage
# arguments themselves.
-
- if empty_argv
- $stderr.puts ARGV.usage
- exit 1
- elsif help_flag
- if cmd.nil?
- puts ARGV.usage
- exit 0
- else
- # Handle both internal ruby and shell commands
- require "cmd/help"
- help_text = Homebrew.help_for_command(cmd)
- if help_text.nil?
- # External command, let it handle help by itself
- elsif help_text.empty?
- opoo "No help available for '#{cmd}' command."
- puts ARGV.usage
- exit 0
- else
- puts help_text
- exit 0
- end
- end
+ if empty_argv || help_flag
+ require "cmd/help"
+ Homebrew.help cmd, empty_argv # Never returns, except for external command.
end
if internal_cmd