MediaWiki master
MediaWiki\Maintenance\MaintenanceParameters Class Reference

Command line parameter handling for maintenance scripts. More...

Public Member Functions

 addArg (string $arg, string $description, bool $required=true, bool $multi=false)
 Define a positional argument.
 
 addOption (string $name, string $description, bool $required=false, bool $withArg=false, $shortName=false, bool $multiOccurrence=false)
 Add a option to the script.
 
 assignGroup (string $groupName, array $paramNames)
 Assigns a list of options to the given group.
 
 clear ()
 Clear all parameter 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 ( $offset=0)
 Get arguments.
 
 getErrors ()
 Get any errors encountered while processing parameters.
 
getFieldReference (string $fieldName)
 Returns a reference to a member field.
 
 getHelp ()
 Get help text.
 
 getName ()
 Get the script name, as shown in the help message.
 
 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, int $skip=0)
 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.
 
 setUsagePrefix (string $usagePrefix)
 
 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 31 of file MaintenanceParameters.php.

Member Function Documentation

◆ addArg()

MediaWiki\Maintenance\MaintenanceParameters::addArg ( string  $arg,
string  $description,
bool  $required = true,
bool  $multi = false 
)

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?
bool$multiDoes it allow multiple values? (Last arg only)
Returns
int the offset of the argument

Definition at line 186 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 option 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 131 of file MaintenanceParameters.php.

◆ assignGroup()

MediaWiki\Maintenance\MaintenanceParameters::assignGroup ( string  $groupName,
array  $paramNames 
)

Assigns a list of options to the given group.

The given options will be shown as part of the given group in the help message.

Parameters
string$groupName
array$paramNames

Definition at line 103 of file MaintenanceParameters.php.

◆ clear()

MediaWiki\Maintenance\MaintenanceParameters::clear ( )

Clear all parameter values.

Note that all parameter definitions remain intact.

Definition at line 339 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 223 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

Definition at line 275 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 305 of file MaintenanceParameters.php.

◆ getArgs()

MediaWiki\Maintenance\MaintenanceParameters::getArgs (   $offset = 0)

Get arguments.

Parameters
int | string$offsetThe index (from zero) of the first argument, or the name declared for the argument by addArg().
Returns
string[]

Definition at line 290 of file MaintenanceParameters.php.

◆ getErrors()

MediaWiki\Maintenance\MaintenanceParameters::getErrors ( )

Get any errors encountered while processing parameters.

Returns
string[]

Definition at line 473 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 91 of file MaintenanceParameters.php.

◆ getHelp()

MediaWiki\Maintenance\MaintenanceParameters::getHelp ( )

Get help text.

Returns
string

Definition at line 567 of file MaintenanceParameters.php.

◆ getName()

MediaWiki\Maintenance\MaintenanceParameters::getName ( )

Get the script name, as shown in the help message.

Returns
string

Definition at line 500 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

Definition at line 168 of file MaintenanceParameters.php.

◆ getOptionNames()

MediaWiki\Maintenance\MaintenanceParameters::getOptionNames ( )

Returns the names of defined options.

Returns
string[]

Definition at line 683 of file MaintenanceParameters.php.

◆ getOptions()

MediaWiki\Maintenance\MaintenanceParameters::getOptions ( )

Returns any option values.

Returns
array

Definition at line 691 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 700 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 258 of file MaintenanceParameters.php.

◆ hasErrors()

MediaWiki\Maintenance\MaintenanceParameters::hasErrors ( )

Whether any errors have been recorded so far.

Returns
bool

Definition at line 482 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 153 of file MaintenanceParameters.php.

◆ loadWithArgv()

MediaWiki\Maintenance\MaintenanceParameters::loadWithArgv ( array  $argv,
int  $skip = 0 
)

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

Parameters
array$argvThe argument array.
int$skipSkip that many elements at the beginning of $argv.

Definition at line 367 of file MaintenanceParameters.php.

◆ mergeOptions()

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

Merge options declarations from $other into this instance.

Parameters
MaintenanceParameters$other

Definition at line 351 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 240 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 327 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 248 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 491 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 316 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 512 of file MaintenanceParameters.php.

◆ setUsagePrefix()

MediaWiki\Maintenance\MaintenanceParameters::setUsagePrefix ( string  $usagePrefix)
Parameters
string$usagePrefix

Definition at line 707 of file MaintenanceParameters.php.

◆ 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 116 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 533 of file MaintenanceParameters.php.


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