Class: TTY::Option::UnpermittedArgument

Inherits:
ParseError
  • Object
show all
Defined in:
lib/tty/option/errors.rb

Overview

Raised when argument value isn’t permitted

Constant Summary collapse

MESSAGE =
"unpermitted value `%<value>s` for '%<name>s' %<type>s: " \
"choose from %<choices>s"

Instance Attribute Summary

Attributes inherited from ParseError

#param

Instance Method Summary collapse

Methods inherited from ParseError

#format_value

Constructor Details

#initialize(param_or_message, value = nil) ⇒ UnpermittedArgument

Returns a new instance of UnpermittedArgument.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/tty/option/errors.rb', line 144

def initialize(param_or_message, value = nil)
  if param_or_message.is_a?(Parameter)
    @param = param_or_message
    message = format(MESSAGE,
                     value: format_value(value),
                     name: param.name,
                     type: param.to_sym,
                     choices: format_choices(param.permit))
  else
    message = param_or_message
  end

  super(message)
end