Skip to content
Snippets Groups Projects
Unverified Commit 2082379a authored by Mike McQuaid's avatar Mike McQuaid Committed by GitHub
Browse files

Revert "help: print cli/parser help message if used"

parent af700b71
No related branches found
No related tags found
No related merge requests found
......@@ -95,7 +95,7 @@ begin
if (empty_argv || help_flag) && cmd != "cask"
require "help"
Homebrew::Help.help cmd, empty_argv: empty_argv
# `Homebrew.help` never returns, except for unknown commands.
# `Homebrew.help` never returns, except for external/unknown commands.
end
if internal_cmd
......
......@@ -16,22 +16,6 @@ module Homebrew
new(args, &block).parse(args)
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
{
quiet: [["-q", "--quiet"], :quiet, "Suppress any warnings."],
......@@ -171,8 +155,7 @@ module Homebrew
end
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(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) }
.gsub(/<(.*?)>/m, "#{Tty.underline}\\1#{Tty.reset}")
......
......@@ -4,6 +4,8 @@ require "formula"
require "erb"
require "ostruct"
require "cli/parser"
# Require all commands
Dir.glob("#{HOMEBREW_LIBRARY_PATH}/{dev-,}cmd/*.rb").sort.each { |cmd| require cmd }
module Homebrew
module_function
......@@ -149,13 +151,19 @@ module Homebrew
# preserve existing manpage order
cmd_paths.sort_by(&method(:sort_key_for_path))
.each do |cmd_path|
cmd_man_page_lines = if cmd_parser = CLI::Parser.from_cmd_path(cmd_path)
cmd_args_method_name = cmd_arg_parser(cmd_path)
cmd_man_page_lines = begin
cmd_parser = Homebrew.send(cmd_args_method_name)
next if cmd_parser.hide_from_man_page
cmd_parser_manpage_lines(cmd_parser).join
else
cmd_comment_manpage_lines(cmd_path)
rescue NoMethodError => e
raise if e.name != cmd_args_method_name
nil
end
cmd_man_page_lines ||= cmd_comment_manpage_lines(cmd_path)
man_page_lines << cmd_man_page_lines
end
......@@ -163,6 +171,10 @@ module Homebrew
man_page_lines.compact.join("\n")
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)
lines = [format_usage_banner(cmd_parser.usage_banner_text)]
lines += cmd_parser.processed_options.map do |short, long, _, desc|
......
......@@ -72,31 +72,37 @@ module Homebrew
# Resume execution in `brew.rb` for unknown commands.
return if path.nil?
# Display help for commands (or generic help if undocumented).
# Display help for internal command (or generic help if undocumented).
puts command_help(path)
exit 0
end
def command_help(path)
# Let OptionParser generate help text for commands which have a parser
if cmd_parser = CLI::Parser.from_cmd_path(path)
return cmd_parser.generate_help_text
# 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
return Homebrew.send(cmd_args_method_name)
.generate_help_text
rescue NoMethodError => e
raise if e.name != cmd_args_method_name
nil
end
# Otherwise read #: lines from the file.
help_lines = command_help_lines(path)
if help_lines.blank?
if help_lines.empty?
opoo "No help text in: #{path}" if ARGV.homebrew_developer?
return HOMEBREW_HELP
HOMEBREW_HELP
else
Formatter.wrap(help_lines.join.gsub(/^ /, ""), COMMAND_DESC_WIDTH)
.sub("@hide_from_man_page ", "")
.sub(/^\* /, "#{Tty.bold}Usage: brew#{Tty.reset} ")
.gsub(/`(.*?)`/m, "#{Tty.bold}\\1#{Tty.reset}")
.gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) }
.gsub(/<(.*?)>/m, "#{Tty.underline}\\1#{Tty.reset}")
.gsub(/\*(.*?)\*/m, "#{Tty.underline}\\1#{Tty.reset}")
end
Formatter.wrap(help_lines.join.gsub(/^ /, ""), COMMAND_DESC_WIDTH)
.sub("@hide_from_man_page ", "")
.sub(/^\* /, "#{Tty.bold}Usage: brew#{Tty.reset} ")
.gsub(/`(.*?)`/m, "#{Tty.bold}\\1#{Tty.reset}")
.gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) }
.gsub(/<(.*?)>/m, "#{Tty.underline}\\1#{Tty.reset}")
.gsub(/\*(.*?)\*/m, "#{Tty.underline}\\1#{Tty.reset}")
end
end
end
......@@ -498,10 +498,7 @@ module Kernel
end
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
def redact_secrets(input, secrets)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment