Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5973832
ExtendedOptsProcessor.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ExtendedOptsProcessor.php
View Options
<?php
namespace
Wikimedia\Parsoid\Tools
;
trait
ExtendedOptsProcessor
{
private
$optionDefaults
=
[];
/**
* @param string $name
* @param mixed $default
*/
public
function
setOptionDefault
(
string
$name
,
$default
)
{
$this
->
optionDefaults
[
$name
]
=
$default
;
}
/**
* Add a parameter to the script with a default value.
* Will be displayed on --help with the associated description.
*
* @param string $name The name of the param (help, version, etc)
* @param string $description The description of the param to show on --help
* @param mixed $defaultValue Default value (default null)
* @param string|bool $shortName Character to use as short name
* @param bool $required Is the param required?
*/
public
function
addOptionWithDefault
(
string
$name
,
string
$description
,
$defaultValue
=
null
,
$shortName
=
false
,
bool
$required
=
false
)
{
$this
->
addOption
(
$name
,
"$description (default: $defaultValue)"
,
$required
,
true
,
/* withArg */
$shortName
,
false
/* multiOccurence */
);
$this
->
setOptionDefault
(
$name
,
$defaultValue
);
}
/** @inheritDoc */
public
function
getOption
(
$name
,
$default
=
null
)
{
return
parent
::
getOption
(
$name
,
$default
??
$this
->
optionDefaults
[
$name
]
??
null
);
}
/**
* Return all known CLI options in an associative array
* @return array
*/
public
function
optionsToArray
():
array
{
return
$this
->
getOptions
()
+
$this
->
optionDefaults
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 16:53 (19 h, 18 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
66/66/ada9681996afea675d4ce25d7098
Default Alt Text
ExtendedOptsProcessor.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment