cli_parser: Add custom description support for global switches
This commit is contained in:
parent
89277adbcc
commit
e32da937a6
@ -42,8 +42,12 @@ module Homebrew
|
|||||||
|
|
||||||
def switch(*names, description: nil, env: nil, required_for: nil, depends_on: nil)
|
def switch(*names, description: nil, env: nil, required_for: nil, depends_on: nil)
|
||||||
global_switch = names.first.is_a?(Symbol)
|
global_switch = names.first.is_a?(Symbol)
|
||||||
names, env, description = common_switch(*names) if global_switch
|
names, env, default_description = common_switch(*names) if global_switch
|
||||||
description = option_to_description(*names) if description.nil?
|
if description.nil? && global_switch
|
||||||
|
description = default_description
|
||||||
|
elsif description.nil?
|
||||||
|
description = option_to_description(*names)
|
||||||
|
end
|
||||||
process_option(*names, description)
|
process_option(*names, description)
|
||||||
@parser.on(*names, *wrap_option_desc(description)) do
|
@parser.on(*names, *wrap_option_desc(description)) do
|
||||||
enable_switch(*names)
|
enable_switch(*names)
|
||||||
|
|||||||
@ -46,6 +46,11 @@ describe Homebrew::CLI::Parser do
|
|||||||
parser.parse([])
|
parser.parse([])
|
||||||
expect(Homebrew.args.pry?).to be true
|
expect(Homebrew.args.pry?).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it ":verbose with custom description" do
|
||||||
|
_, _, _, desc = parser.processed_options.find { |short, _| short == "-v" }
|
||||||
|
expect(desc).to eq "Flag for verbosity"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "test long flag options" do
|
describe "test long flag options" do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user