Skip to content

Commit

Permalink
Fix consolidation#304: use native Symfony Negatable input options.
Browse files Browse the repository at this point in the history
  • Loading branch information
manarth committed Dec 20, 2023
1 parent e01152f commit 7b1b010
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/Parser/CommandInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,24 +551,9 @@ public function inputOptions()
return $this->inputOptions;
}

protected function addImplicitNoOptions()
{
$opts = $this->options()->getValues();
foreach ($opts as $name => $defaultValue) {
if ($defaultValue === true) {
$key = 'no-' . $name;
if (!array_key_exists($key, $opts)) {
$description = "Negate --$name option.";
$this->options()->add($key, $description, false);
}
}
}
}

protected function createInputOptions()
{
$explicitOptions = [];
$this->addImplicitNoOptions();

$opts = $this->options()->getValues();
foreach ($opts as $name => $defaultValue) {
Expand All @@ -590,7 +575,13 @@ protected function createInputOptions()
$defaultValue = null;
}

if ($defaultValue === false) {
if ($defaultValue === true) {
$explicitOptions[$fullName] = new InputOption(
$fullName,
$shortcut,
InputOption::VALUE_NONE | InputOption::VALUE_NEGATABLE,
$description);
} elseif ($defaultValue === false) {
$explicitOptions[$fullName] = new InputOption($fullName, $shortcut, InputOption::VALUE_NONE, $description);
} elseif ($defaultValue === InputOption::VALUE_REQUIRED) {
$explicitOptions[$fullName] = new InputOption($fullName, $shortcut, InputOption::VALUE_REQUIRED, $description, null, $suggestedValues);
Expand Down

0 comments on commit 7b1b010

Please sign in to comment.