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

Merge pull request #5095 from EricFromCanada/cli-parser-help

cli_parser: improve help text formatting
parents 9b84b240 6b872443
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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
......
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