help: improve command --help output.

This commit is contained in:
Mike McQuaid 2019-01-30 21:34:21 +00:00
parent 1bdcd2001c
commit 4ace1af297
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
2 changed files with 9 additions and 5 deletions

View File

@ -76,10 +76,13 @@ module Homebrew
def command_help(path)
# Let OptionParser generate help text for commands which have a parser defined
begin
cmd = path.basename(path.extname)
return Homebrew.send("#{cmd.to_s.tr("-", "_")}_args".to_sym).generate_help_text
rescue NoMethodError
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
@ -89,7 +92,8 @@ module Homebrew
HOMEBREW_HELP
else
help_lines.map do |line|
line.sub(/^ \* /, "#{Tty.bold}brew#{Tty.reset} ")
line.gsub(/^ /, "")
.sub(/^\* /, "#{Tty.bold}Usage: brew#{Tty.reset} ")
.gsub(/`(.*?)`/, "#{Tty.bold}\\1#{Tty.reset}")
.gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) }
.gsub(/<(.*?)>/, "#{Tty.underline}\\1#{Tty.reset}")

View File

@ -20,7 +20,7 @@ describe "brew", :integration_test do
it "prints help for a documented shell command" do
expect { brew "help", "update" }
.to output(/^brew update/).to_stdout
.to output(/^Usage: brew update/).to_stdout
.and be_a_success
end