Validation
Note:
validatein use universally as of v0.41.0.
validate
Validate a value by type
Usage
validate handler type name value
Validation sets are passed as three arguments, optionally repeated: type name value
Types are case-insensitive:
Text and formats
EmptyString- (aliasstring?,any) - Any value at allString- (no aliases) - Any non-empty stringEnvironmentVariable- (aliasenv) - A non-empty string which contains alphanumeric characters or the underscore and does not begin with a digit.Secret- (no aliases) - A value which is security sensitiveDate- (no aliases) - A valid date in the formYYYY-MM-DDURL- (no aliases) - A Universal Resource Locator in the formscheme://user:password@host:port/path
Numbers
Flag- (no aliases) - Presence of an option to enables a feature. (e.g.--debugis aflag)Boolean- (aliasbool) - A valuetrueorfalseBooleanLike- (aliasesboolean?,bool?) - A value which should be evaluated to a boolean valueInteger- (aliasint) - Any integer, positive or negativeUnsignedInteger- (aliasesuint,unsigned) - Any integer 0 or greaterPositiveInteger- (aliaspositive) - Any integer 1 or greaterNumber- (aliasnumber) - Any integer or real number
File system
Exists- (no aliases - A file (or directory) which exists in the file system of any typeFile- (no aliases) - A file which exists in the file system which is not any special typeLink- (no aliases) - A link which exists in the file systemDirectory- (aliasdir) - A directory which exists in the file systemDirectoryList- (aliasdirlist) - One or more directories as argumentsFileDirectory- (aliasparent) - A file whose directory exists in the file system but which may or may not exist.RealDirectory- (aliasrealdir) - The real path of a directory which must exist.RealFile- (aliasreal) - The real path of a file which must exist.RemoteDirectory- (aliasremotedir) - The path to a directory on a remote host.
Application-relative
ApplicationDirectory- (aliasappdir) - A directory path relative toBUILD_HOMEApplicationFile- (aliasappfile) - A file path relative toBUILD_HOMEApplicationDirectoryList- (aliasappdirlist) - One or more arguments of typeApplicationDirectory
Functional
Type- (no aliases) - A type which can be validated byvalidateFunction- (aliasfunction) - A defined functionCallable- (aliascallable) - A function or executableExecutable- (aliasbin) - Any binary available within thePATH
Lists
Array- (no aliases) - Zero or more argumentsList- (no aliases) - Zero or more argumentsColonDelimitedList- (aliaslist:) - A colon-delimited list:CommaDelimitedList- (aliaslist,) - A comma-delimited list,You can repeat thetypenamevaluemore than once in the arguments and each will be checked until one failsvalidateis intended to be extensible as well as reducible to smaller sizes by limiting type validation to used types only. The core validation types can be used CASE-SENSITIVE ONLY in smaller scripts using the corevalidateidentical document which includes:StringPositiveIntegerFunctionCallableTypeThe function_validateTypeMapperis defined and can map types to internal types. If not present, then no conversion is done. For a type to be considered valid, the corresponding__validateTypeprefixed function MUST exist. Internally the function_validateTypeMapperDefaultis the default type mapper and does the stringLowercase and alias lookups.
Arguments
handler- Function. Required. Error handler.type- Type. Required. Type to validate. If more than validation set is specified, specifying atypeof "" inherits the previoustype. Blanktypesare not allowed.name- String. Required. Name of the variable which is being validated. If more than validation set is specified, specifying a name of "" inherits the previous name. Blank names are not allowed.value- EmptyString. Required. Value to validate.
Return codes
0- Valid is valid, stdout is a filtered version of the value to be used2- Valid is invalid, output reason to stderr
validateTypeList
List types which can be validated
Usage
validateTypeList
List types which can be validated
Arguments
- none
Return codes
0- Success1- Environment error2- Argument error
isValidateType
Are all arguments passed a valid validate type?
Usage
isValidateType [ --help ] [ type ]
Are all arguments passed a valid validate type?
Arguments
--help- Flag. Optional. Display this help.type- String. Optional. Type to validate asvalidatetype.
Examples
isValidateType string || returnMessage 1 "string is not a type."
Return codes
0- Success1- Environment error2- Argument error