-
Notifications
You must be signed in to change notification settings - Fork 51
Command Arguments
Bertie2011 edited this page Aug 29, 2021
·
2 revisions
Arguments are positional parameters, which means you'll receive them in the order they were specified. No special registration is required as arguments will work out of the box, but you can register arguments to improve help output and add validation.
To register arguments, start by overriding the public function arguments($args): void
method. Then register each argument using the chainable and optional methods below.
$args->add('name')
->desc('description')
->optional()
->multiple()
->isa('number'|'boolean'|'string')
->validValues([$val1, $val2]) //uses in_array() internally
->validator(callable) //Does not receive arguments, should return boolean
->suggestions([$val1, $val2] | callable | string); //If string and starts with "zsh:", will be translated into zsh function call.
You can get the arguments by simply specifying arguments in the execute method (see Lifecycle Hooks) or by using func_get_args()
inside the execute method.