cli_parser: Add custom description support for global switches

This commit is contained in:
Gautham Goli 2018-10-24 17:10:13 +05:30
parent 89277adbcc
commit e32da937a6
No known key found for this signature in database
GPG Key ID: 6A9ABBC284468364
2 changed files with 11 additions and 2 deletions

View File

@ -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)

View File

@ -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