-
Notifications
You must be signed in to change notification settings - Fork 6
Builtin Validations
mosop edited this page Dec 31, 2016
·
11 revisions
Tests if a parsed value is any of the specified values.
Can be applied to:
- String Option
- String Argument
class SomewhereWarm < Optarg::Model
arg "island", any_of: %w(tahiti okinawa hawaii)
end
SomewhereWarm.parse %w(gotland) # => raises an error
Tests if a parsed element value of array is any of the specified values.
Can be applied to:
- String Array Option
- String Array Argument
class EuropeanWallet < Optarg::Model
arg_array "bill", any_item_of: %w(€5 €10 €20 €50 €100 €200 €500)
end
EuropeanWallet.parse %w(€10 $50 €100) # => raises an error
Tests if the count of parsed elements of array is equal to or greater than the specified number.
Can be applied to:
- String Array Option
- String Array Argument
class TeamOfCanoePolo < Optarg::Model
arg_array "member", min: 5
end
TeamOfCanoePolo.parse %w(freddie brian roger john) # => raises an error
Tests if a value is set.
Can be applied to:
- String Option
- String Argument
class GoToProm < Optarg::Model
string "--dress"
string "--partner", required: true
end
GoToProm.parse %w(--dress brand-new-tuxedo) # => raises an error