Revert "Revert "help: print cli/parser help message if used""
This commit is contained in:
parent
2d21fa0928
commit
eb87651341
@ -95,7 +95,7 @@ begin
|
|||||||
if (empty_argv || help_flag) && cmd != "cask"
|
if (empty_argv || help_flag) && cmd != "cask"
|
||||||
require "help"
|
require "help"
|
||||||
Homebrew::Help.help cmd, empty_argv: empty_argv
|
Homebrew::Help.help cmd, empty_argv: empty_argv
|
||||||
# `Homebrew.help` never returns, except for external/unknown commands.
|
# `Homebrew.help` never returns, except for unknown commands.
|
||||||
end
|
end
|
||||||
|
|
||||||
if internal_cmd
|
if internal_cmd
|
||||||
|
@ -16,6 +16,22 @@ module Homebrew
|
|||||||
new(args, &block).parse(args)
|
new(args, &block).parse(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.from_cmd_path(cmd_path)
|
||||||
|
cmd_method_prefix = cmd_path.basename(cmd_path.extname)
|
||||||
|
.to_s
|
||||||
|
.sub(/^brew-/, "")
|
||||||
|
.tr("-", "_")
|
||||||
|
cmd_args_method_name = "#{cmd_method_prefix}_args".to_sym
|
||||||
|
|
||||||
|
begin
|
||||||
|
Homebrew.send(cmd_args_method_name) if require?(cmd_path)
|
||||||
|
rescue NoMethodError => e
|
||||||
|
raise if e.name != cmd_args_method_name
|
||||||
|
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.global_options
|
def self.global_options
|
||||||
{
|
{
|
||||||
quiet: [["-q", "--quiet"], :quiet, "Suppress any warnings."],
|
quiet: [["-q", "--quiet"], :quiet, "Suppress any warnings."],
|
||||||
@ -159,7 +175,8 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generate_help_text
|
def generate_help_text
|
||||||
@parser.to_s.sub(/^/, "#{Tty.bold}Usage: brew#{Tty.reset} ")
|
@parser.to_s
|
||||||
|
.sub(/^/, "#{Tty.bold}Usage: brew#{Tty.reset} ")
|
||||||
.gsub(/`(.*?)`/m, "#{Tty.bold}\\1#{Tty.reset}")
|
.gsub(/`(.*?)`/m, "#{Tty.bold}\\1#{Tty.reset}")
|
||||||
.gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) }
|
.gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) }
|
||||||
.gsub(/<(.*?)>/m, "#{Tty.underline}\\1#{Tty.reset}")
|
.gsub(/<(.*?)>/m, "#{Tty.underline}\\1#{Tty.reset}")
|
||||||
|
@ -4,8 +4,6 @@ require "formula"
|
|||||||
require "erb"
|
require "erb"
|
||||||
require "ostruct"
|
require "ostruct"
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
# Require all commands
|
|
||||||
Dir.glob("#{HOMEBREW_LIBRARY_PATH}/{dev-,}cmd/*.rb").sort.each { |cmd| require cmd }
|
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module_function
|
||||||
@ -151,19 +149,13 @@ module Homebrew
|
|||||||
# preserve existing manpage order
|
# preserve existing manpage order
|
||||||
cmd_paths.sort_by(&method(:sort_key_for_path))
|
cmd_paths.sort_by(&method(:sort_key_for_path))
|
||||||
.each do |cmd_path|
|
.each do |cmd_path|
|
||||||
cmd_args_method_name = cmd_arg_parser(cmd_path)
|
cmd_man_page_lines = if cmd_parser = CLI::Parser.from_cmd_path(cmd_path)
|
||||||
|
|
||||||
cmd_man_page_lines = begin
|
|
||||||
cmd_parser = Homebrew.send(cmd_args_method_name)
|
|
||||||
next if cmd_parser.hide_from_man_page
|
next if cmd_parser.hide_from_man_page
|
||||||
|
|
||||||
cmd_parser_manpage_lines(cmd_parser).join
|
cmd_parser_manpage_lines(cmd_parser).join
|
||||||
rescue NoMethodError => e
|
else
|
||||||
raise if e.name != cmd_args_method_name
|
cmd_comment_manpage_lines(cmd_path)
|
||||||
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
cmd_man_page_lines ||= cmd_comment_manpage_lines(cmd_path)
|
|
||||||
|
|
||||||
man_page_lines << cmd_man_page_lines
|
man_page_lines << cmd_man_page_lines
|
||||||
end
|
end
|
||||||
@ -171,10 +163,6 @@ module Homebrew
|
|||||||
man_page_lines.compact.join("\n")
|
man_page_lines.compact.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def cmd_arg_parser(cmd_path)
|
|
||||||
"#{cmd_path.basename.to_s.gsub(".rb", "").tr("-", "_")}_args".to_sym
|
|
||||||
end
|
|
||||||
|
|
||||||
def cmd_parser_manpage_lines(cmd_parser)
|
def cmd_parser_manpage_lines(cmd_parser)
|
||||||
lines = [format_usage_banner(cmd_parser.usage_banner_text)]
|
lines = [format_usage_banner(cmd_parser.usage_banner_text)]
|
||||||
lines += cmd_parser.processed_options.map do |short, long, _, desc|
|
lines += cmd_parser.processed_options.map do |short, long, _, desc|
|
||||||
|
@ -72,29 +72,24 @@ module Homebrew
|
|||||||
# Resume execution in `brew.rb` for unknown commands.
|
# Resume execution in `brew.rb` for unknown commands.
|
||||||
return if path.nil?
|
return if path.nil?
|
||||||
|
|
||||||
# Display help for internal command (or generic help if undocumented).
|
# Display help for commands (or generic help if undocumented).
|
||||||
puts command_help(path)
|
puts command_help(path)
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def command_help(path)
|
def command_help(path)
|
||||||
# Let OptionParser generate help text for commands which have a parser defined
|
# Let OptionParser generate help text for commands which have a parser
|
||||||
cmd = path.basename(path.extname)
|
if cmd_parser = CLI::Parser.from_cmd_path(path)
|
||||||
cmd_args_method_name = "#{cmd.to_s.tr("-", "_")}_args".to_sym
|
return cmd_parser.generate_help_text
|
||||||
begin
|
|
||||||
return Homebrew.send(cmd_args_method_name)
|
|
||||||
.generate_help_text
|
|
||||||
rescue NoMethodError => e
|
|
||||||
raise if e.name != cmd_args_method_name
|
|
||||||
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Otherwise read #: lines from the file.
|
||||||
help_lines = command_help_lines(path)
|
help_lines = command_help_lines(path)
|
||||||
if help_lines.empty?
|
if help_lines.blank?
|
||||||
opoo "No help text in: #{path}" if ARGV.homebrew_developer?
|
opoo "No help text in: #{path}" if ARGV.homebrew_developer?
|
||||||
HOMEBREW_HELP
|
return HOMEBREW_HELP
|
||||||
else
|
end
|
||||||
|
|
||||||
Formatter.wrap(help_lines.join.gsub(/^ /, ""), COMMAND_DESC_WIDTH)
|
Formatter.wrap(help_lines.join.gsub(/^ /, ""), COMMAND_DESC_WIDTH)
|
||||||
.sub("@hide_from_man_page ", "")
|
.sub("@hide_from_man_page ", "")
|
||||||
.sub(/^\* /, "#{Tty.bold}Usage: brew#{Tty.reset} ")
|
.sub(/^\* /, "#{Tty.bold}Usage: brew#{Tty.reset} ")
|
||||||
@ -104,5 +99,4 @@ module Homebrew
|
|||||||
.gsub(/\*(.*?)\*/m, "#{Tty.underline}\\1#{Tty.reset}")
|
.gsub(/\*(.*?)\*/m, "#{Tty.underline}\\1#{Tty.reset}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -498,7 +498,10 @@ module Kernel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def command_help_lines(path)
|
def command_help_lines(path)
|
||||||
path.read.lines.grep(/^#:/).map { |line| line.slice(2..-1) }
|
path.read
|
||||||
|
.lines
|
||||||
|
.grep(/^#:/)
|
||||||
|
.map { |line| line.slice(2..-1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def redact_secrets(input, secrets)
|
def redact_secrets(input, secrets)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user