| 1 |
module Slop |
| 2 |
# Base error class. |
| 3 |
class Error < StandardError |
| 4 |
end |
| 5 |
|
| 6 |
# Raised when calling `call` on Slop::Option (this |
| 7 |
# method must be overriden in subclasses) |
| 8 |
class NotImplementedError < Error |
| 9 |
end |
| 10 |
|
| 11 |
# Raised when an option that expects an argument is |
| 12 |
# executed without one. Suppress with the `suppress_errors` |
| 13 |
# config option. |
| 14 |
class MissingArgument < Error |
| 15 |
attr_reader :flags |
| 16 |
|
| 17 |
# Get all the flags that matches |
| 18 |
# the option with the missing argument |
| 19 |
def initialize(msg, flags) |
| 20 |
super(msg) |
| 21 |
@flags = flags |
| 22 |
end |
| 23 |
end |
| 24 |
|
| 25 |
# Raised when an unknown option is parsed or when trying to fetch an |
| 26 |
# unexisting option via `Slop::Result#fetch`. |
| 27 |
# Suppress with the `suppress_errors` config option. |
| 28 |
class UnknownOption < Error |
| 29 |
attr_reader :flag |
| 30 |
|
| 31 |
def initialize(msg, flag) |
| 32 |
super(msg) |
| 33 |
@flag = flag |
| 34 |
end |
| 35 |
end |
| 36 |
|
| 37 |
# Raised when a required option is *not* parsed. |
| 38 |
# Suppress with the `suppress_errors` config option. |
| 39 |
class MissingRequiredOption < Error |
| 40 |
end |
| 41 |
|
| 42 |
# Raised when a given option is provided by the user and does not |
| 43 |
# match the expected format for that type. This is only raised if |
| 44 |
# validate_types is set to true. |
| 45 |
class InvalidOptionValue < Error |
| 46 |
attr_reader :flag |
| 47 |
|
| 48 |
def initialize(msg, flag) |
| 49 |
super(msg) |
| 50 |
@flag = flag |
| 51 |
end |
| 52 |
end |
| 53 |
end |