cli/parser: Improve single or multi "-" detection

- This reads nicer (to me).
This commit is contained in:
Issy Long 2020-12-24 15:53:13 +00:00
parent 570a660758
commit 27afcf5779
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4

View File

@ -533,8 +533,8 @@ module Homebrew
class OptionConstraintError < UsageError
def initialize(arg1, arg2, missing: false)
arg1 = arg1.length > 1 ? "--#{arg1.tr("_", "-")}" : "-#{arg1.tr("_", "-")}"
arg2 = arg2.length > 1 ? "--#{arg2.tr("_", "-")}" : "-#{arg2.tr("_", "-")}"
arg1 = dashes(arg1) + arg1.tr("_", "-")
arg2 = dashes(arg2) + arg2.tr("_", "-")
message = if missing
"`#{arg2}` cannot be passed without `#{arg1}`."
@ -543,6 +543,10 @@ module Homebrew
end
super message
end
def dashes(arg)
arg.length > 1 ? "--" : "-"
end
end
class OptionConflictError < UsageError