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

Constructor Details

#initialize(param_or_message, value = nil) ⇒ UnpermittedArgument

Returns a new instance of UnpermittedArgument.


128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/tty/option/errors.rb', line 128

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

  super(message)
end