Class Option
An input option.
Args options are passed after the command name(s). Each option has a long name that is prefixed by two dashes ("--") and optionally a short name that is prefixed by one dash only ("-"). The long name must have at least two characters, the short name must contain a single letter only.
In the example below, "--verbose" and "-v" are the long and short names of the same option:
$ console server --verbose
$ console server -v
The long and short names are passed to the constructor of this class. The leading dashes can be omitted:
$option = new Option('verbose', 'v');
If an option accepts a value, you must pass one of the flags
VALUE_REQUIRED, VALUE_OPTIONAL or Webmozart\Console\Api\Args\Format\Option::MULTI_VALUED
to
the constructor:
$option = new Option('format', 'f', Option::VALUE_REQUIRED);
- The flag VALUE_REQUIRED indicates that a value must always be passed. * The flag VALUE_OPTIONAL indicates that a value may optionally be passed. If no value is passed, the default value passed to the constructor is returned, which defaults to
null
. * The flagWebmozart\Console\Api\Args\Format\Option::MULTI_VALUED
indicates that the option can be passed multiple times with different values. The passed values are returned to the application as array. The value of a multi-valued option is always required.
- Webmozart\Console\Api\Args\Format\AbstractOption
- Webmozart\Console\Api\Args\Format\Option
Author: Bernhard Schussek bschussek@gmail.com
Since: 1.0
Located at Api/Args/Format/Option.php
public
|
#
__construct( string $longName, string|null $shortName = null, integer $flags = 0, string $description = null, mixed $defaultValue = null, string $valueName = '...' )
Creates a new option. |
public
boolean
|
|
public
mixed
|
|
public
boolean
|
|
public
boolean
|
|
public
boolean
|
|
public
|
|
public
mixed
|
|
public
string
|
getDescription(),
getLongName(),
getShortName(),
isLongNamePreferred(),
isShortNamePreferred()
|
integer |
NO_VALUE
Flag: The option has no value. |
#
4
|
integer |
REQUIRED_VALUE
Flag: The option has a required value. |
#
8
|
integer |
OPTIONAL_VALUE
Flag: The option has an optional value. |
#
16
|
integer |
MULTI_VALUED
Flag: The option can be stated multiple times with different values. |
#
32
|
integer |
STRING
Flag: The option value is parsed as string. |
#
128
|
integer |
BOOLEAN
Flag: The option value is parsed as boolean. |
#
256
|
integer |
INTEGER
Flag: The option value is parsed as integer. |
#
512
|
integer |
FLOAT
Flag: The option value is parsed as float. |
#
1024
|
integer |
NULLABLE
Flag: The option value "null" should be parsed as |
#
2048
|
PREFER_LONG_NAME,
PREFER_SHORT_NAME
|
$flags
|