Creates instance of DelegateValidator
Validator function type
Validates input
Validator function
Checks whenever specified input is valid.
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 )
validateWith, validateEachWith
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.