From 4ace1af297b633b1297a57650f5ca85c5aa9becb Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 30 Jan 2019 21:34:21 +0000 Subject: [PATCH] help: improve command --help output. --- Library/Homebrew/help.rb | 12 ++++++++---- Library/Homebrew/test/cmd/help_spec.rb | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/help.rb b/Library/Homebrew/help.rb index 671a962afc..6b734c3b70 100644 --- a/Library/Homebrew/help.rb +++ b/Library/Homebrew/help.rb @@ -76,10 +76,13 @@ module Homebrew 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 - cmd = path.basename(path.extname) - return Homebrew.send("#{cmd.to_s.tr("-", "_")}_args".to_sym).generate_help_text - rescue NoMethodError + 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}") diff --git a/Library/Homebrew/test/cmd/help_spec.rb b/Library/Homebrew/test/cmd/help_spec.rb index ab80b69f01..df4b7dd3c3 100644 --- a/Library/Homebrew/test/cmd/help_spec.rb +++ b/Library/Homebrew/test/cmd/help_spec.rb @@ -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