diff --git a/Library/Homebrew/cli_parser.rb b/Library/Homebrew/cli_parser.rb index 0de33a37e7..17b21cdca7 100644 --- a/Library/Homebrew/cli_parser.rb +++ b/Library/Homebrew/cli_parser.rb @@ -35,11 +35,8 @@ module Homebrew def post_initialize @parser.on_tail("-h", "--help", "Show this message") do - puts @parser.to_s.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}") - exit + puts generate_help_text + exit 0 end end @@ -128,6 +125,13 @@ module Homebrew Homebrew::CLI::Parser.global_options.key?(name.to_sym) end + def generate_help_text + @parser.to_s.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}") + end + private def enable_switch(*names) diff --git a/Library/Homebrew/help.rb b/Library/Homebrew/help.rb index a73ad81981..d541081c8d 100644 --- a/Library/Homebrew/help.rb +++ b/Library/Homebrew/help.rb @@ -38,14 +38,6 @@ module Homebrew module_function def help(cmd = nil, flags = {}) - # Let OptionParser generate help text for commands which have a parser defined - begin - Homebrew.send("#{cmd.tr("-", "_")}_args".to_sym) - return - rescue NoMethodError - nil - end - # Resolve command aliases and find file containing the implementation. if cmd cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd) @@ -83,6 +75,14 @@ module Homebrew end 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 + nil + end + help_lines = command_help_lines(path) if help_lines.empty? opoo "No help text in: #{path}" if ARGV.homebrew_developer? diff --git a/Library/Homebrew/test/cmd/help_spec.rb b/Library/Homebrew/test/cmd/help_spec.rb index 6d94d7444c..e3460dec0f 100644 --- a/Library/Homebrew/test/cmd/help_spec.rb +++ b/Library/Homebrew/test/cmd/help_spec.rb @@ -26,7 +26,7 @@ describe "brew", :integration_test do it "prints help for a documented Ruby developer command" do expect { brew "help", "update-test" } - .to output(/^brew update-test/).to_stdout + .to output(/^Usage: brew update-test/).to_stdout .and be_a_success end