help_spec: fix and generate help text in help.rb
This commit is contained in:
parent
38feaf1270
commit
b5b988cbb1
@ -35,11 +35,8 @@ module Homebrew
|
|||||||
|
|
||||||
def post_initialize
|
def post_initialize
|
||||||
@parser.on_tail("-h", "--help", "Show this message") do
|
@parser.on_tail("-h", "--help", "Show this message") do
|
||||||
puts @parser.to_s.sub(/^/, "#{Tty.bold}Usage: brew#{Tty.reset} ")
|
puts generate_help_text
|
||||||
.gsub(/`(.*?)`/, "#{Tty.bold}\\1#{Tty.reset}")
|
exit 0
|
||||||
.gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) }
|
|
||||||
.gsub(/<(.*?)>/, "#{Tty.underline}\\1#{Tty.reset}")
|
|
||||||
exit
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -128,6 +125,13 @@ module Homebrew
|
|||||||
Homebrew::CLI::Parser.global_options.key?(name.to_sym)
|
Homebrew::CLI::Parser.global_options.key?(name.to_sym)
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def enable_switch(*names)
|
def enable_switch(*names)
|
||||||
|
|||||||
@ -38,14 +38,6 @@ module Homebrew
|
|||||||
module_function
|
module_function
|
||||||
|
|
||||||
def help(cmd = nil, flags = {})
|
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.
|
# Resolve command aliases and find file containing the implementation.
|
||||||
if cmd
|
if cmd
|
||||||
cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
|
cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
|
||||||
@ -83,6 +75,14 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def command_help(path)
|
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)
|
help_lines = command_help_lines(path)
|
||||||
if help_lines.empty?
|
if help_lines.empty?
|
||||||
opoo "No help text in: #{path}" if ARGV.homebrew_developer?
|
opoo "No help text in: #{path}" if ARGV.homebrew_developer?
|
||||||
|
|||||||
@ -26,7 +26,7 @@ describe "brew", :integration_test do
|
|||||||
|
|
||||||
it "prints help for a documented Ruby developer command" do
|
it "prints help for a documented Ruby developer command" do
|
||||||
expect { brew "help", "update-test" }
|
expect { brew "help", "update-test" }
|
||||||
.to output(/^brew update-test/).to_stdout
|
.to output(/^Usage: brew update-test/).to_stdout
|
||||||
.and be_a_success
|
.and be_a_success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user