Module: Homebrew::Help

Defined in:
brew/Library/Homebrew/help.rb

Class Method Summary collapse

Class Method Details

.command_help(path) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'brew/Library/Homebrew/help.rb', line 80

def command_help(path)
  # Let OptionParser generate help text for commands which have a parser defined
  cmd = path.basename(path.extname)
  cmd_args_method_name = "#{cmd.to_s.tr("-", "_")}_args".to_sym
  begin
    return Homebrew.send(cmd_args_method_name)
                   .generate_help_text
  rescue NoMethodError => e
    raise if e.name != cmd_args_method_name

    nil
  end

  help_lines = command_help_lines(path)
  if help_lines.empty?
    opoo "No help text in: #{path}" if ARGV.homebrew_developer?
    HOMEBREW_HELP
  else
    Formatter.wrap(help_lines.join.gsub(/^  /, ""), COMMAND_DESC_WIDTH)
             .sub("@hide_from_man_page ", "")
             .sub(/^\* /, "#{Tty.bold}Usage: brew#{Tty.reset} ")
             .gsub(/`(.*?)`/m, "#{Tty.bold}\\1#{Tty.reset}")
             .gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) }
             .gsub(/<(.*?)>/m, "#{Tty.underline}\\1#{Tty.reset}")
             .gsub(/\*(.*?)\*/m, "#{Tty.underline}\\1#{Tty.reset}")
  end
end

.help(cmd = nil, flags = {}) ⇒ Object



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
73
74
75
76
77
78
# File 'brew/Library/Homebrew/help.rb', line 43

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 = Commands.path(cmd)
    path ||= which("brew-#{cmd}")
    path ||= which("brew-#{cmd}.rb")
  end

  # Display command-specific (or generic) help in response to `UsageError`.
  if (error_message = flags[:usage_error])
    $stderr.puts path ? command_help(path) : HOMEBREW_HELP
    $stderr.puts
    onoe error_message
    exit 1
  end

  # Handle `brew` (no arguments).
  if flags[: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

  # 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(path)
  exit 0
end