Class ConsoleInputOption
An object to represent a single option used in the command line. ConsoleOptionParser creates these when you use addOption()
Property Summary
-
$_boolean protected
bool
Is the option a boolean option. Boolean options do not consume a parameter.
-
$_choices protected
list<string>
An array of choices for the option.
-
$_default protected
string|bool|null
Default value for the option
-
$_help protected
string
Help text for the option.
-
$_multiple protected
bool
Can the option accept multiple value definition.
-
$_name protected
string
Name of the option
-
$_short protected
string
Short (1 character) alias for the option.
-
$prompt protected
string|null
The prompt string
-
$required protected
bool
Is the option required.
Method Summary
-
__construct() public
Make a new Input Option
-
acceptsMultiple() public
Check if this option accepts multiple values.
-
choices() public
Get the list of choices this option has.
-
defaultValue() public
Get the default value for this option
-
help() public
Generate the help for this this option.
-
isBoolean() public
Check if this option is a boolean option
-
isRequired() public
Check if this option is required
-
name() public
Get the value of the name attribute.
-
prompt() public
Get the prompt string
-
short() public
Get the value of the short attribute.
-
usage() public
Get the usage value for this option
-
validChoice() public
Check that a value is a valid choice for this option.
-
xml() public
Append the option's XML into the parent.
Method Detail
__construct() ¶ public
__construct(string $name, string $short = '', string $help = '', bool $isBoolean = false, string|bool|null $default = null, list<string> $choices = [], bool $multiple = false, bool $required = false, string|null $prompt = null)
Make a new Input Option
Parameters
-
string
$name The long name of the option, or an array with all the properties.
-
string
$short optional The short alias for this option
-
string
$help optional The help text for this option
-
bool
$isBoolean optional Whether this option is a boolean option. Boolean options don't consume extra tokens
-
string|bool|null
$default optional The default value for this option.
-
list<string>
$choices optional Valid choices for this option.
-
bool
$multiple optional Whether this option can accept multiple value definition.
-
bool
$required optional Whether this option is required or not.
-
string|null
$prompt optional The prompt string.
Throws
Cake\Console\Exception\ConsoleException
acceptsMultiple() ¶ public
acceptsMultiple(): bool
Check if this option accepts multiple values.
Returns
bool
defaultValue() ¶ public
defaultValue(): string|bool|null
Get the default value for this option
Returns
string|bool|null
help() ¶ public
help(int $width = 0): string
Generate the help for this this option.
Parameters
-
int
$width optional The width to make the name of the option.
Returns
string
validChoice() ¶ public
validChoice(string|bool $value): true
Check that a value is a valid choice for this option.
Parameters
-
string|bool
$value The choice to validate.
Returns
true
Throws
Cake\Console\Exception\ConsoleException
xml() ¶ public
xml(SimpleXMLElement $parent): SimpleXMLElement
Append the option's XML into the parent.
Parameters
-
SimpleXMLElement
$parent The parent element.
Returns
SimpleXMLElement
Property Detail
$_boolean ¶ protected
Is the option a boolean option. Boolean options do not consume a parameter.
Type
bool