DelegateValidator

Validates input based on delegate.

Delegate receives all arguments that IValidator.validate receives, that is information about entry being checked and an array of values to perform check on.

For less verbose usage, check validateWith and validateEachWith helper functions.

Constructors

this
this(ValidatorFunc validator)

Creates instance of DelegateValidator

Members

Aliases

ValidatorFunc
alias ValidatorFunc = void delegate(IEntry, string[])

Validator function type

Functions

validate
void validate(IEntry entry, string[] args)

Validates input

Variables

validator
ValidatorFunc validator;

Validator function

Inherited Members

From IValidator

validate
void validate(IEntry entry, string[] values)

Checks whenever specified input is valid.

Examples

1 new Program("rm")
2     .add(new Argument("target", "target to remove")
3         .validate(new DelegateValidator((entry, args) {
4              foreach (arg; args) {
5                  if (arg == "foo") throw new ValidationException("invalid number"); // would throw with "invalid number"
6              }
7         }))
8         // or
9         .validateEachWith((entry, arg) {
10              if (arg == "5") throw new ValidationException("invalid number"); // would throw with "invalid number"
11         })
12         // or
13         .validateEachWith(arg => isGood(arg), "must be good") // would throw with "flag a must be good"
14     )

See Also

validateWith, validateEachWith

Meta