MediaWiki REL1_39
MediaWiki\Maintenance\MaintenanceParameters Class Reference

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.
 

Detailed Description

Command line parameter handling for maintenance scripts.

Since
1.39

Definition at line 29 of file MaintenanceParameters.php.

Member Function Documentation

◆ addArg()

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.

Parameters
string$argName of the arg, like 'start'
string$descriptionShort description of the arg
bool$requiredIs this required?
Returns
int the offset of the argument

Definition at line 180 of file MaintenanceParameters.php.

◆ addOption()

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

Parameters
string$nameThe name of the param (help, version, etc)
string$descriptionThe description of the param to show on –help
bool$requiredIs the param required?
bool$withArgIs an argument required with this option?
string | bool$shortNameCharacter to use as short name
bool$multiOccurrenceCan this option be passed multiple times?

Definition at line 126 of file MaintenanceParameters.php.

◆ assignGroup()

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.

Parameters
string$groupName
array$paramNames

Definition at line 98 of file MaintenanceParameters.php.

◆ clear()

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.

◆ deleteOption()

MediaWiki\Maintenance\MaintenanceParameters::deleteOption ( string $name)

Remove an option.

Useful for removing options that won't be used in your script.

Parameters
string$nameThe option to remove.

Definition at line 196 of file MaintenanceParameters.php.

◆ getArg()

MediaWiki\Maintenance\MaintenanceParameters::getArg ( $argId,
?string $default = null )

Get an argument.

Parameters
int | string$argIdThe index (from zero) of the argument, or the name declared for the argument by addArg().
string | null$defaultThe default if it doesn't exist
Returns
string|null
-taint none

Definition at line 248 of file MaintenanceParameters.php.

◆ getArgName()

MediaWiki\Maintenance\MaintenanceParameters::getArgName ( int $argIndex)

Get the name of an argument at the given index.

Parameters
int$argIndexThe integer value (from zero) for the arg
Returns
?string the name of the argument, or null if no name is defined for that argument

Definition at line 264 of file MaintenanceParameters.php.

◆ getArgs()

MediaWiki\Maintenance\MaintenanceParameters::getArgs ( )

Returns argument values.

Returns
array

Definition at line 640 of file MaintenanceParameters.php.

◆ getErrors()

MediaWiki\Maintenance\MaintenanceParameters::getErrors ( )

Get any errors encountered while processing parameters.

Returns
string[]

Definition at line 425 of file MaintenanceParameters.php.

◆ getFieldReference()

& 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!

Parameters
string$fieldName
Returns
mixed A reference to a member field
Access: internal
For use by the Maintenance class, for backwards compatibility support.

Definition at line 86 of file MaintenanceParameters.php.

◆ getHelp()

MediaWiki\Maintenance\MaintenanceParameters::getHelp ( )

Get help text.

Returns
string

Definition at line 510 of file MaintenanceParameters.php.

◆ getOption()

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.

Parameters
string$nameThe name of the param
mixed | null$defaultAnything you want, default null
Returns
mixed
-taint none

Definition at line 163 of file MaintenanceParameters.php.

◆ getOptionNames()

MediaWiki\Maintenance\MaintenanceParameters::getOptionNames ( )

Returns the names of defined options.

Returns
string[]

Definition at line 615 of file MaintenanceParameters.php.

◆ getOptions()

MediaWiki\Maintenance\MaintenanceParameters::getOptions ( )

Returns any option values.

Returns
array

Definition at line 623 of file MaintenanceParameters.php.

◆ getOptionsSequence()

MediaWiki\Maintenance\MaintenanceParameters::getOptionsSequence ( )

Returns option values as an ordered sequence.

Useful for option chaining (Ex. dumpBackup.php).

Returns
array[] a list of pairs of like [ $option, $value ]

Definition at line 632 of file MaintenanceParameters.php.

◆ hasArg()

MediaWiki\Maintenance\MaintenanceParameters::hasArg ( $argId)

Was a value for the given argument provided?

Parameters
int | string$argIdThe index (from zero) of the argument, or the name declared for the argument by addArg().
Returns
bool

Definition at line 231 of file MaintenanceParameters.php.

◆ hasErrors()

MediaWiki\Maintenance\MaintenanceParameters::hasErrors ( )

Whether any errors have been recorded so far.

Returns
bool

Definition at line 434 of file MaintenanceParameters.php.

◆ hasOption()

MediaWiki\Maintenance\MaintenanceParameters::hasOption ( string $name)

Checks to see if a particular option was set.

Parameters
string$nameThe name of the option
Returns
bool

Definition at line 148 of file MaintenanceParameters.php.

◆ loadWithArgv()

MediaWiki\Maintenance\MaintenanceParameters::loadWithArgv ( array $argv)

Load params and arguments from a given array of command-line arguments.

Parameters
array$argv

Definition at line 323 of file MaintenanceParameters.php.

References $args.

◆ mergeOptions()

MediaWiki\Maintenance\MaintenanceParameters::mergeOptions ( MaintenanceParameters $other)

Merge options declarations from $other into this instance.

Parameters
MaintenanceParameters$other

Definition at line 310 of file MaintenanceParameters.php.

◆ setAllowUnregisteredOptions()

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.

Parameters
bool$allowShould we allow?

Definition at line 213 of file MaintenanceParameters.php.

◆ setArg()

MediaWiki\Maintenance\MaintenanceParameters::setArg ( $argId,
$value )

Programmatically set the value of the given argument.

Useful for setting up child scripts, see runChild().

Parameters
string | int$argId
string$value

Definition at line 286 of file MaintenanceParameters.php.

◆ setDescription()

MediaWiki\Maintenance\MaintenanceParameters::setDescription ( string $text)

Set a short description of what the script does.

Parameters
string$text

Definition at line 221 of file MaintenanceParameters.php.

◆ setName()

MediaWiki\Maintenance\MaintenanceParameters::setName ( string $name)

Set the script name, for use in the help message.

Parameters
string$name

Definition at line 443 of file MaintenanceParameters.php.

◆ setOption()

MediaWiki\Maintenance\MaintenanceParameters::setOption ( string $name,
$value )

Programmatically set the value of the given option.

Useful for setting up child scripts, see runChild().

Parameters
string$name
mixed | null$value

Definition at line 275 of file MaintenanceParameters.php.

◆ setOptionsAndArgs()

MediaWiki\Maintenance\MaintenanceParameters::setOptionsAndArgs ( array $opts,
array $args )

Force option and argument values.

Access: internal
Parameters
array$opts
array$args

Definition at line 455 of file MaintenanceParameters.php.

References $args.

◆ supportsOption()

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.

Parameters
string$nameThe name of the option<string,string>
Returns
bool true if the option exists, false otherwise

Definition at line 111 of file MaintenanceParameters.php.

◆ validate()

MediaWiki\Maintenance\MaintenanceParameters::validate ( )

Run some validation checks on the params, etc.

Error details can be obtained via getErrors().

Returns
bool

Definition at line 476 of file MaintenanceParameters.php.


The documentation for this class was generated from the following file: