diff options
| author | Martin Afanasjew | 2016-04-17 03:45:10 +0200 | 
|---|---|---|
| committer | Martin Afanasjew | 2016-04-18 00:52:32 +0200 | 
| commit | 3503806e772ad0c5cfc4311bb816c1735c5b9e81 (patch) | |
| tree | b639d6149668c85501f6b922eecdd6720b0affa4 /Library/Homebrew/cmd/help.rb | |
| parent | 144d86f73315f59d65234ace69880bb9d3a90acb (diff) | |
| download | brew-3503806e772ad0c5cfc4311bb816c1735c5b9e81.tar.bz2 | |
help: handle help output (move from 'brew.rb')
Keep the footprint of `brew.rb` small. Handle fetching/displaying an
appropriate help text (taking into account various external conditions)
in the `help` command.
Diffstat (limited to 'Library/Homebrew/cmd/help.rb')
| -rw-r--r-- | Library/Homebrew/cmd/help.rb | 28 | 
1 files changed, 26 insertions, 2 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") | 
