From 6b8724431fb73b75f003064cb4b70c20e9e665e0 Mon Sep 17 00:00:00 2001 From: EricFromCanada Date: Sat, 6 Oct 2018 22:52:47 -0400 Subject: [PATCH] cli_parser: improve help text formatting - reduce desc_line_length so `brew help` output fits in 80 columns - support special formatting across line breaks - support emphasis using asterisks - add missing depends_on: tests --- Library/Homebrew/cli_parser.rb | 9 +++++---- Library/Homebrew/help.rb | 1 + Library/Homebrew/test/cli_parser_spec.rb | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cli_parser.rb b/Library/Homebrew/cli_parser.rb index 17b21cdca7..844bc9130c 100644 --- a/Library/Homebrew/cli_parser.rb +++ b/Library/Homebrew/cli_parser.rb @@ -28,13 +28,13 @@ module Homebrew @constraints = [] @conflicts = [] @processed_options = [] - @desc_line_length = 48 + @desc_line_length = 43 instance_eval(&block) post_initialize end def post_initialize - @parser.on_tail("-h", "--help", "Show this message") do + @parser.on_tail("-h", "--help", "Show this message.") do puts generate_help_text exit 0 end @@ -127,9 +127,10 @@ module Homebrew def generate_help_text @parser.to_s.sub(/^/, "#{Tty.bold}Usage: brew#{Tty.reset} ") - .gsub(/`(.*?)`/, "#{Tty.bold}\\1#{Tty.reset}") + .gsub(/`(.*?)`/m, "#{Tty.bold}\\1#{Tty.reset}") .gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) } - .gsub(/<(.*?)>/, "#{Tty.underline}\\1#{Tty.reset}") + .gsub(/<(.*?)>/m, "#{Tty.underline}\\1#{Tty.reset}") + .gsub(/\*(.*?)\*/m, "#{Tty.underline}\\1#{Tty.reset}") end private diff --git a/Library/Homebrew/help.rb b/Library/Homebrew/help.rb index d541081c8d..671a962afc 100644 --- a/Library/Homebrew/help.rb +++ b/Library/Homebrew/help.rb @@ -93,6 +93,7 @@ module Homebrew .gsub(/`(.*?)`/, "#{Tty.bold}\\1#{Tty.reset}") .gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) } .gsub(/<(.*?)>/, "#{Tty.underline}\\1#{Tty.reset}") + .gsub(/\*(.*?)\*/, "#{Tty.underline}\\1#{Tty.reset}") .gsub("@hide_from_man_page", "") end.join.strip end diff --git a/Library/Homebrew/test/cli_parser_spec.rb b/Library/Homebrew/test/cli_parser_spec.rb index ba1f8c4ae8..a2f294e78e 100644 --- a/Library/Homebrew/test/cli_parser_spec.rb +++ b/Library/Homebrew/test/cli_parser_spec.rb @@ -89,6 +89,7 @@ describe Homebrew::CLI::Parser do it "raises exception on depends_on constraint violation" do expect { parser.parse(["--flag2=flag2"]) }.to raise_error(Homebrew::CLI::OptionConstraintError) + expect { parser.parse(["--flag4=flag4"]) }.to raise_error(Homebrew::CLI::OptionConstraintError) end it "raises exception for conflict violation" do @@ -139,6 +140,7 @@ describe Homebrew::CLI::Parser do it "raises exception on depends_on constraint violation" do expect { parser.parse(["--switch-c"]) }.to raise_error(Homebrew::CLI::OptionConstraintError) + expect { parser.parse(["--switch-d"]) }.to raise_error(Homebrew::CLI::OptionConstraintError) end it "raises exception for conflict violation" do