Class: Toys::ArgParser::UsageError
- Inherits:
-
Object
- Object
- Toys::ArgParser::UsageError
- Defined in:
- lib/toys/arg_parser.rb
Overview
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.
Direct Known Subclasses
ArgMissingError, ArgValueUnacceptableError, ExtraArgumentsError, FlagAmbiguousError, FlagGroupConstraintError, FlagUnrecognizedError, FlagValueMissingError, FlagValueNotAllowedError, FlagValueUnacceptableError, ToolUnrecognizedError
Instance Attribute Summary collapse
-
#message ⇒ String
readonly
The basic error message.
-
#name ⇒ String?
readonly
The name of the element (normally a flag or positional argument) that reported the error.
-
#suggestions ⇒ Array<String>?
readonly
An array of suggestions from DidYouMean.
-
#value ⇒ String?
readonly
The value that was rejected.
Instance Method Summary collapse
-
#full_message ⇒ String
(also: #to_s)
A fully formatted error message including suggestions.
-
#initialize(message, name: nil, value: nil, suggestions: nil) ⇒ UsageError
constructor
Create a UsageError given a message and common data.
Constructor Details
#initialize(message, name: nil, value: nil, suggestions: nil) ⇒ UsageError
Create a UsageError given a message and common data
30 31 32 33 34 35 |
# File 'lib/toys/arg_parser.rb', line 30 def initialize(, name: nil, value: nil, suggestions: nil) @message = @name = name @value = value @suggestions = suggestions end |
Instance Attribute Details
#message ⇒ String (readonly)
The basic error message. Does not include suggestions, if any.
42 43 44 |
# File 'lib/toys/arg_parser.rb', line 42 def @message end |
#name ⇒ String? (readonly)
The name of the element (normally a flag or positional argument) that reported the error.
51 52 53 |
# File 'lib/toys/arg_parser.rb', line 51 def name @name end |
#suggestions ⇒ Array<String>? (readonly)
An array of suggestions from DidYouMean.
67 68 69 |
# File 'lib/toys/arg_parser.rb', line 67 def suggestions @suggestions end |
#value ⇒ String? (readonly)
The value that was rejected.
59 60 61 |
# File 'lib/toys/arg_parser.rb', line 59 def value @value end |
Instance Method Details
#full_message ⇒ String Also known as: to_s
A fully formatted error message including suggestions.
74 75 76 77 78 79 80 81 |
# File 'lib/toys/arg_parser.rb', line 74 def if suggestions && !suggestions.empty? alts_str = suggestions.join("\n ") "#{}\nDid you mean... #{alts_str}" else end end |