Skip to content
Bertie2011 edited this page Aug 29, 2021 · 1 revision

Options are like named parameters. The parameter can have a short name, a long name or both. A short name is a single character and is specified starting with just a single dash, like -f. A long name can be of any length, but must not contain any spaces and is specified starting with two dashes like --file. After the name follows an equals sign or a space and then the value. Optionally surrounded with quotes if it contains special characters or a space.

To define options, override public function options($opts): void in a command class. See the GetOptionKit package wiki and examples for more information.

Example:

$opts->add('f|file:', 'Specify the value of an argument.');

Which allows:

command -f value
command -f=value
command --file value
command --file=value

You can get the values of options by using $this->getOptions(). Retrieve single values using the short or long name like any other field: $this->getOptions()->f or $this->getOptions()->file.