8000 [Console] Added three state long option by ocke · Pull Request #11883 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[Console] Added three state long option #11883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
renamed to flagValue
  • Loading branch information
Olaf Kwant committed Sep 10, 2014
commit a18724f7d5ef5c78a3857b28958895d383247dee
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Input/ArgvInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private function addLongOption($name, $value)
if ($option->isArray()) {
$this->options[$name][] = $value;
} elseif ($option->isValueTernary() && true === $value) {
$this->options[$name] = $option->getSetDefault();
$this->options[$name] = $option->getFlagValue();
} else {
$this->options[$name] = $value;
}
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/Console/Input/InputOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InputOption
private $shortcut;
private $mode;
private $default;
private $setDefault;
private $flagValue;
private $description;

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ public function isArray()
}

/**
* Returns true if the option takes an optional value with false as default and setDefault as default
* Returns true if the option takes an optional value with false as default and flagValue as default
*
* @return bool true if mode is self::VALUE_TERNARY, false otherwise
*/
Expand All @@ -165,7 +165,7 @@ public function isValueTernary()
* Sets the default value.
*
* For VALUE_TERNARY the $default will always be set to false (for when the long option is not used)
* and $setDefault will be used to store the default (for when the long option is used without a value)
* and $flagValue will be used to store the default (for when the long option is used without a value)
*
* @param mixed $default The default value
*
Expand All @@ -185,14 +185,14 @@ public function setDefault($default = null)
}
}

$setDefault = false;
$flagValue = false;

if ($this->isValueTernary()) {
$setDefault = $default;
$flagValue = $default;
$default = false;
}

$this->setDefault = $setDefault;
$this->flagValue = $flagValue;
$this->default = $this->acceptValue() ? $default : false;
}

Expand All @@ -211,9 +211,9 @@ public function getDefault()
*
* @return mixed The default value
*/
public function getSetDefault()
public function getFlagValue()
{
return $this->setDefault;
return $this->flagValue;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Console/Tests/Input/InputOptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ public function testGetDefault()
}


public function testGetSetDefault()
public function testGetFlagValue()
{
$option = new InputOption('foo');
$this->assertEquals(false, $option->getSetDefault(), '->getDefault() returns false');
$this->assertEquals(false, $option->getFlagValue(), '->getDefault() returns false');

$option = new InputOption('foo', null, InputOption::VALUE_TERNARY);
$this->assertEquals(null, $option->getSetDefault(), '->getDefault() returns null if the option does not have a value');
$this->assertEquals(null, $option->getFlagValue(), '->getDefault() returns null if the option does not have a value');

$option = new InputOption('foo', null, InputOption::VALUE_TERNARY, '', 'default');
$this->assertEquals('default', $option->getSetDefault(), '->getDefault() returns the default value');
$this->assertEquals('default', $option->getFlagValue(), '->getDefault() returns the default value');
}

public function testSetDefault()
Expand Down
0