cli/parser: Option-ify arg names when raising OptionConstraintError
- There's already a method on `CLI::Parser`, we don't need to hand-roll the "number of dashes" detection. Co-authored-by: Rylan Polster <rslpolster@gmail.com>
This commit is contained in:
parent
27afcf5779
commit
531cae4b8c
@ -432,6 +432,10 @@ module Homebrew
|
||||
@constraints.each do |primary, secondary, constraint_type|
|
||||
primary_passed = option_passed?(primary)
|
||||
secondary_passed = option_passed?(secondary)
|
||||
|
||||
primary = name_to_option(primary)
|
||||
secondary = name_to_option(secondary)
|
||||
|
||||
if :mandatory.equal?(constraint_type) && primary_passed && !secondary_passed
|
||||
raise OptionConstraintError.new(primary, secondary)
|
||||
end
|
||||
@ -533,9 +537,6 @@ module Homebrew
|
||||
|
||||
class OptionConstraintError < UsageError
|
||||
def initialize(arg1, arg2, missing: false)
|
||||
arg1 = dashes(arg1) + arg1.tr("_", "-")
|
||||
arg2 = dashes(arg2) + arg2.tr("_", "-")
|
||||
|
||||
message = if missing
|
||||
"`#{arg2}` cannot be passed without `#{arg1}`."
|
||||
else
|
||||
@ -543,10 +544,6 @@ module Homebrew
|
||||
end
|
||||
super message
|
||||
end
|
||||
|
||||
def dashes(arg)
|
||||
arg.length > 1 ? "--" : "-"
|
||||
end
|
||||
end
|
||||
|
||||
class OptionConflictError < UsageError
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user