From e32da937a6a51ca87e3f156764583951fccc3521 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Wed, 24 Oct 2018 17:10:13 +0530 Subject: [PATCH] cli_parser: Add custom description support for global switches --- Library/Homebrew/cli_parser.rb | 8 ++++++-- Library/Homebrew/test/cli_parser_spec.rb | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cli_parser.rb b/Library/Homebrew/cli_parser.rb index 844bc9130c..7f98f7411d 100644 --- a/Library/Homebrew/cli_parser.rb +++ b/Library/Homebrew/cli_parser.rb @@ -42,8 +42,12 @@ module Homebrew def switch(*names, description: nil, env: nil, required_for: nil, depends_on: nil) global_switch = names.first.is_a?(Symbol) - names, env, description = common_switch(*names) if global_switch - description = option_to_description(*names) if description.nil? + names, env, default_description = common_switch(*names) if global_switch + if description.nil? && global_switch + description = default_description + elsif description.nil? + description = option_to_description(*names) + end process_option(*names, description) @parser.on(*names, *wrap_option_desc(description)) do enable_switch(*names) diff --git a/Library/Homebrew/test/cli_parser_spec.rb b/Library/Homebrew/test/cli_parser_spec.rb index a2f294e78e..d3f3bc98bc 100644 --- a/Library/Homebrew/test/cli_parser_spec.rb +++ b/Library/Homebrew/test/cli_parser_spec.rb @@ -46,6 +46,11 @@ describe Homebrew::CLI::Parser do parser.parse([]) expect(Homebrew.args.pry?).to be true end + + it ":verbose with custom description" do + _, _, _, desc = parser.processed_options.find { |short, _| short == "-v" } + expect(desc).to eq "Flag for verbosity" + end end describe "test long flag options" do