You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Déclare la classe CommandLine\Argument\Option\OptionFlagWithReverse.
|
|
*/
|
|
|
|
namespace jrosset\CommandLine\Argument\Option;
|
|
|
|
/**
|
|
* Option de type "flag" : vaut True ou False avec son tag inversé.
|
|
*
|
|
* Le tag long inversé est automatiquement généré en préfixant avec "no-" sauf si l'initial commence déjà par "no-".
|
|
* Le tag court inversé est fait de la même manière, mais avec le préfixe "n".
|
|
*
|
|
* Exemples :
|
|
* - "--force" donne "--no-force"
|
|
* - "-f" donne "-nf"
|
|
* - "--no-stop" devient "--stop"
|
|
*
|
|
* @package CommandLine\Argument\Option
|
|
*/
|
|
class FlagWithReverse extends Flag implements IArgumentOptionSecondary {
|
|
public function getOthersOptions (): array {
|
|
$tagShort = null;
|
|
if ($this->hasTagShort()) {
|
|
if (substr($this->getTagShort(), 0, 1) == 'n') {
|
|
$tagShort = substr($this->getTagShort(), 1);
|
|
}
|
|
else {
|
|
$tagShort = 'n' . $this->getTagShort();
|
|
}
|
|
}
|
|
|
|
if (substr($this->getTagLong(), 0, 3) == 'no-') {
|
|
$tagLong = substr($this->getTagLong(), 3);
|
|
}
|
|
else {
|
|
$tagLong = 'no-' . $this->getTagLong();
|
|
}
|
|
|
|
$name = $this->getName();
|
|
if (substr($name, 0, 3) == 'no') {
|
|
$name = strtolower(substr($name, 2, 1)) . substr($name, 3);
|
|
}
|
|
else {
|
|
$name = 'no' . strtoupper(substr($name, 0, 1)) . substr($name, 1);
|
|
}
|
|
|
|
$description = '[INVERSE] ' . $this->getDescription();
|
|
|
|
$reverse = new Flag($name, !$this->getDefault(), $description, $tagLong, $tagShort);
|
|
$reverse->setVarName($this->getVarName());
|
|
|
|
return array($reverse);
|
|
}
|
|
} |