Exception: Brut::CLI::InvalidOption

Inherits:
Error
  • Object
show all
Defined in:
lib/brut/cli/error.rb

Overview

Raised when an OptionParser::ParseError is caught to provide a more useful error message given the global/command optiona dichotomy.

Instance Method Summary collapse

Constructor Details

#initialize(option_parser_parse_error, context:) ⇒ InvalidOption

Returns a new instance of InvalidOption.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/brut/cli/error.rb', line 25

def initialize(option_parser_parse_error, context:)
  args = option_parser_parse_error.args
  count_message = if option_parser_parse_error.args.length == 1
                    "isn't a valid option"
                  else
                    "aren't valid options"
                  end
  type_message = if context.kind_of?(Class)
                   "for the '#{context.command_name}' command"
                 else
                   "for the app globally"
                 end
  super("#{args.join(", ")} #{count_message} #{type_message}")
end