parser: allow a disabled switch to specify its replacement

This commit is contained in:
EricFromCanada 2020-11-27 14:41:05 -05:00 committed by Mike McQuaid
parent 0604005405
commit b7aae0c643
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70

View File

@ -139,13 +139,19 @@ module Homebrew
instance_eval(&block) if block
end
def switch(*names, description: nil, env: nil, required_for: nil, depends_on: nil, method: :on)
def switch(*names, description: nil, replacement: nil, env: nil, required_for: nil, depends_on: nil,
method: :on)
global_switch = names.first.is_a?(Symbol)
return if global_switch
description = option_to_description(*names) if description.nil?
process_option(*names, description)
if replacement.nil?
process_option(*names, description)
else
description += " (disabled#{"; replaced by #{replacement}" if replacement.present?})"
end
@parser.public_send(method, *names, *wrap_option_desc(description)) do |value|
odisabled "the `#{names.first}` switch", replacement unless replacement.nil?
value = if names.any? { |name| name.start_with?("--[no-]") }
value
else