Module: Homebrew::Help Private

Defined in:
help.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper module for printing help output.

Class Method Summary collapse

Class Method Details

.help(cmd = nil, empty_argv: false, usage_error: nil, remaining_args: []) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'help.rb', line 42

def self.help(cmd = nil, empty_argv: false, usage_error: nil, remaining_args: [])
  if cmd.nil?
    # Handle `brew` (no arguments).
    if empty_argv
      $stderr.puts HOMEBREW_HELP
      exit 1
    end

    # Handle `brew (-h|--help|--usage|-?|help)` (no other arguments).
    puts HOMEBREW_HELP
    exit 0
  end

  # Resolve command aliases and find file containing the implementation.
  path = Commands.path(cmd)

  # Display command-specific (or generic) help in response to `UsageError`.
  if usage_error
    $stderr.puts path ? command_help(cmd, path, remaining_args:) : HOMEBREW_HELP
    $stderr.puts
    onoe usage_error
    exit 1
  end

  # Resume execution in `brew.rb` for unknown commands.
  return if path.nil?

  # Display help for internal command (or generic help if undocumented).
  puts command_help(cmd, path, remaining_args:)
  exit 0
end