CLI
CLI
Properties
options
private array $options
commands
private array $commands
opt
private array $opt
Methods
init
public init({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$args | array |
setCommands
Sets the available commands.
public setCommands({Array})
Format of $commands
is an array where the key is the name of the command and:
- Index 0 is the help description of the command.
- Index 1 is a string or array of optional parameters.
Example:
$cli->SetCommands([
'test' => ['Execute a test', ['when']],
'exit' => ['Exit the CLI']
]);
If a command is specified on the CLI when executing the program it will be returned with $cli->getCommand()
.
Parameters
Parameter | Type | Description |
---|---|---|
$commands | array |
setOptions
Sets the available options.
public setOptions({Array})
Format of $options
is an array where the key is the name of the option and:
- Index 0 is the 'short name' of the option. See: getopts().
- Index 1 is the 'long name' of the option. See: getopts().
- Index 2 is the name of an optional parameter.
- Index 3 is the help description displayed on the help page.
- Index 4 is the name of a command that the options is limited to. Optional.
Example:
$cli->setOptions([
'help' => ['h', 'help', null, 'Display this help message.'],
'timeout' => ['t', 'timeout', 'seconds', 'Enable test mode.'],
'force' => ['f', 'force', null, 'Force things to happen.', 'command'],
])
Options are then available using $cli->getOptions()
which will return an array of the options specified on the CLI. If they have a parameter, that parameter will be the value, otherwise the value will be TRUE.
Parameters
Parameter | Type | Description |
---|---|---|
$options | array<mixed> |
getCommand
Gets the command that was used on the command line if it exists.
public getCommand({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$args | array | an array of arguments that were specified after the command |
getOptions
Returns the currently applied options from the ARGV command line options.
public getOptions({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$posArgs | NULL |
showHelp
Shows a help page on the CLI for the options and commands that have been configured.
public showHelp({Array})
Generated by Hazaar API Doc Generator