MediaWiki REL1_39
|
Command line parameter handling for maintenance scripts. More...
Public Member Functions | |
addArg (string $arg, string $description, bool $required=true) | |
Define a positional argument. | |
addOption (string $name, string $description, bool $required=false, bool $withArg=false, $shortName=false, bool $multiOccurrence=false) | |
Add a parameter to the script. | |
assignGroup (string $groupName, array $paramNames) | |
Assigns a list of parameters to the given group. | |
clear () | |
Clear all parameter and argument values. | |
deleteOption (string $name) | |
Remove an option. | |
getArg ( $argId, ?string $default=null) | |
Get an argument. | |
getArgName (int $argIndex) | |
Get the name of an argument at the given index. | |
getArgs () | |
Returns argument values. | |
getErrors () | |
Get any errors encountered while processing parameters. | |
& | getFieldReference (string $fieldName) |
Returns a reference to a member field. | |
getHelp () | |
Get help text. | |
getOption (string $name, $default=null) | |
Get the value of an option, or return the default. | |
getOptionNames () | |
Returns the names of defined options. | |
getOptions () | |
Returns any option values. | |
getOptionsSequence () | |
Returns option values as an ordered sequence. | |
hasArg ( $argId) | |
Was a value for the given argument provided? | |
hasErrors () | |
Whether any errors have been recorded so far. | |
hasOption (string $name) | |
Checks to see if a particular option was set. | |
loadWithArgv (array $argv) | |
Load params and arguments from a given array of command-line arguments. | |
mergeOptions (MaintenanceParameters $other) | |
Merge options declarations from $other into this instance. | |
setAllowUnregisteredOptions (bool $allow) | |
Sets whether to allow unknown options to be passed to the script. | |
setArg ( $argId, $value) | |
Programmatically set the value of the given argument. | |
setDescription (string $text) | |
Set a short description of what the script does. | |
setName (string $name) | |
Set the script name, for use in the help message. | |
setOption (string $name, $value) | |
Programmatically set the value of the given option. | |
setOptionsAndArgs (array $opts, array $args) | |
Force option and argument values. | |
supportsOption (string $name) | |
Checks to see if a particular option in supported. | |
validate () | |
Run some validation checks on the params, etc. | |
Command line parameter handling for maintenance scripts.
Definition at line 29 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::addArg | ( | string | $arg, |
string | $description, | ||
bool | $required = true ) |
Define a positional argument.
getArg() can later be used to get the value given for the argument, by index or by name.
string | $arg | Name of the arg, like 'start' |
string | $description | Short description of the arg |
bool | $required | Is this required? |
Definition at line 180 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::addOption | ( | string | $name, |
string | $description, | ||
bool | $required = false, | ||
bool | $withArg = false, | ||
$shortName = false, | |||
bool | $multiOccurrence = false ) |
Add a parameter to the script.
Will be displayed on –help with the associated description
string | $name | The name of the param (help, version, etc) |
string | $description | The description of the param to show on –help |
bool | $required | Is the param required? |
bool | $withArg | Is an argument required with this option? |
string | bool | $shortName | Character to use as short name |
bool | $multiOccurrence | Can this option be passed multiple times? |
Definition at line 126 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::assignGroup | ( | string | $groupName, |
array | $paramNames ) |
Assigns a list of parameters to the given group.
The given parameters will be shown as part of the given group in the help message.
string | $groupName | |
array | $paramNames |
Definition at line 98 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::clear | ( | ) |
Clear all parameter and argument values.
Note that all parameter definitions remain intact.
Definition at line 298 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::deleteOption | ( | string | $name | ) |
Remove an option.
Useful for removing options that won't be used in your script.
string | $name | The option to remove. |
Definition at line 196 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::getArg | ( | $argId, | |
?string | $default = null ) |
Get an argument.
int | string | $argId | The index (from zero) of the argument, or the name declared for the argument by addArg(). |
string | null | $default | The default if it doesn't exist |
Definition at line 248 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::getArgName | ( | int | $argIndex | ) |
Get the name of an argument at the given index.
int | $argIndex | The integer value (from zero) for the arg |
Definition at line 264 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::getArgs | ( | ) |
MediaWiki\Maintenance\MaintenanceParameters::getErrors | ( | ) |
Get any errors encountered while processing parameters.
Definition at line 425 of file MaintenanceParameters.php.
& MediaWiki\Maintenance\MaintenanceParameters::getFieldReference | ( | string | $fieldName | ) |
Returns a reference to a member field.
This is a backwards compatibility hack, it should be removed as soon as possible!
string | $fieldName |
Definition at line 86 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::getHelp | ( | ) |
MediaWiki\Maintenance\MaintenanceParameters::getOption | ( | string | $name, |
$default = null ) |
Get the value of an option, or return the default.
If the option was defined to support multiple occurrences, this will return an array.
string | $name | The name of the param |
mixed | null | $default | Anything you want, default null |
Definition at line 163 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::getOptionNames | ( | ) |
Returns the names of defined options.
Definition at line 615 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::getOptions | ( | ) |
MediaWiki\Maintenance\MaintenanceParameters::getOptionsSequence | ( | ) |
Returns option values as an ordered sequence.
Useful for option chaining (Ex. dumpBackup.php).
Definition at line 632 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::hasArg | ( | $argId | ) |
Was a value for the given argument provided?
int | string | $argId | The index (from zero) of the argument, or the name declared for the argument by addArg(). |
Definition at line 231 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::hasErrors | ( | ) |
Whether any errors have been recorded so far.
Definition at line 434 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::hasOption | ( | string | $name | ) |
Checks to see if a particular option was set.
string | $name | The name of the option |
Definition at line 148 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::loadWithArgv | ( | array | $argv | ) |
Load params and arguments from a given array of command-line arguments.
array | $argv |
Definition at line 323 of file MaintenanceParameters.php.
References $args.
MediaWiki\Maintenance\MaintenanceParameters::mergeOptions | ( | MaintenanceParameters | $other | ) |
Merge options declarations from $other into this instance.
MaintenanceParameters | $other |
Definition at line 310 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::setAllowUnregisteredOptions | ( | bool | $allow | ) |
Sets whether to allow unknown options to be passed to the script.
Per default, unknown options cause an error.
bool | $allow | Should we allow? |
Definition at line 213 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::setArg | ( | $argId, | |
$value ) |
Programmatically set the value of the given argument.
Useful for setting up child scripts, see runChild().
string | int | $argId | |
string | $value |
Definition at line 286 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::setDescription | ( | string | $text | ) |
Set a short description of what the script does.
string | $text |
Definition at line 221 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::setName | ( | string | $name | ) |
Set the script name, for use in the help message.
string | $name |
Definition at line 443 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::setOption | ( | string | $name, |
$value ) |
Programmatically set the value of the given option.
Useful for setting up child scripts, see runChild().
string | $name | |
mixed | null | $value |
Definition at line 275 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::setOptionsAndArgs | ( | array | $opts, |
array | $args ) |
Force option and argument values.
array | $opts | |
array | $args |
Definition at line 455 of file MaintenanceParameters.php.
References $args.
MediaWiki\Maintenance\MaintenanceParameters::supportsOption | ( | string | $name | ) |
Checks to see if a particular option in supported.
Normally this means it has been registered by the script via addOption.
string | $name | The name of the option<string,string> |
Definition at line 111 of file MaintenanceParameters.php.
MediaWiki\Maintenance\MaintenanceParameters::validate | ( | ) |
Run some validation checks on the params, etc.
Error details can be obtained via getErrors().
Definition at line 476 of file MaintenanceParameters.php.