Class: Toys::ArgParser::UsageError

Inherits:
Object
  • Object
show all
Defined in:
core-docs/toys/arg_parser.rb

Overview

Defined in the toys-core gem

Base representation of a usage error reported by the ArgParser.

This functions similarly to an exception, but is not raised. Rather, it is returned in the #errors array.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, name: nil, value: nil, suggestions: nil) ⇒ UsageError

Create a UsageError given a message and common data

Parameters:

  • message (String)

    The basic error message.

  • name (String, nil) (defaults to: nil)

    The name of the element (normally flag or positional argument) that reported the error, or nil if there is no definite element.

  • value (String, nil) (defaults to: nil)

    The value that was rejected, or nil if not applicable.

  • suggestions (Array<String>, nil) (defaults to: nil)

    An array of suggestions from DidYouMean, or nil if not applicable.



32
33
34
# File 'core-docs/toys/arg_parser.rb', line 32

def initialize(message, name: nil, value: nil, suggestions: nil)
  # Source available in the toys-core gem
end

Instance Attribute Details

#messageString (readonly)

The basic error message. Does not include suggestions, if any.

Returns:

  • (String)


41
42
43
# File 'core-docs/toys/arg_parser.rb', line 41

def message
  @message
end

#nameString? (readonly)

The name of the element (normally a flag or positional argument) that reported the error.

Returns:

  • (String)

    The element name.

  • (nil)

    if there is no definite element source.



50
51
52
# File 'core-docs/toys/arg_parser.rb', line 50

def name
  @name
end

#suggestionsArray<String>? (readonly)

An array of suggestions from DidYouMean.

Returns:

  • (Array<String>)

    array of suggestions.

  • (nil)

    if suggestions are not applicable to this error.



66
67
68
# File 'core-docs/toys/arg_parser.rb', line 66

def suggestions
  @suggestions
end

#valueString? (readonly)

The value that was rejected.

Returns:

  • (String)

    the value string

  • (nil)

    if a value is not applicable to this error.



58
59
60
# File 'core-docs/toys/arg_parser.rb', line 58

def value
  @value
end

Instance Method Details

#full_messageString Also known as: to_s

A fully formatted error message including suggestions.

Returns:

  • (String)


73
74
75
# File 'core-docs/toys/arg_parser.rb', line 73

def full_message
  # Source available in the toys-core gem
end