From 531cae4b8c18689212474a4235f9061471ca3b40 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 24 Dec 2020 16:29:44 +0000 Subject: [PATCH] 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 --- Library/Homebrew/cli/parser.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 2cbafcbcc8..0db260c0a4 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -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