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

Skip to content

[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
name changes and comment about the difference between default and set…
…Default
  • Loading branch information
Olaf Kwant committed Sep 10, 2014
commit 8b6588115eb46e1252abcddbac2e6ec448508e5c
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 @@ -249,7 +249,7 @@ private function addLongOption($name, $value)

if ($option->isArray()) {
$this->options[$name][] = $value;
} elseif ($option->isValueOptionull() && true === $value) {
} elseif ($option->isValueTernary() && true === $value) {
$this->options[$name] = $option->getSetDefault();
} else {
$this->options[$name] = $value;
Expand Down
15 changes: 9 additions & 6 deletions src/Symfony/Component/Console/Input/InputOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function getName()
*/
public function acceptValue()
{
return $this->isValueRequired() || $this->isValueOptional() || $this->isValueOptionull();
return $this->isValueRequired() || $this->isValueOptional() || $this->isValueTernary();
}

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

/**
* Returns true if the option takes an optional value with null as default.
* Returns true if the option takes an optional value with false as default and setDefault as default
*
* @return bool true if mode is self::VALUE_TERNARY, false otherwise
*/
public function isValueOptionull()
public function isValueTernary()
{
return self::VALUE_TERNARY === (self::VALUE_TERNARY & $this->mode);
}

/**
* Sets the default value.
*
* For VALUE_TERNARY the $default will always be set to false (for when the longoption is not used)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space: long option

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, why talking about long option here ? It is true for shortcuts too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ok, I'll fix that

* and $setDefault will be used to store the default (for when the longoption is used without a value)
*
* @param mixed $default The default value
*
* @throws \LogicException When incorrect default value is given
Expand All @@ -184,7 +187,7 @@ public function setDefault($default = null)

$setDefault = false;

if ($this->isValueOptionull()) {
if ($this->isValueTernary()) {
$setDefault = $default;
$default = false;
}
Expand All @@ -204,7 +207,7 @@ public function getDefault()
}

/**
* Returns the default value.
* Returns the default value for a longoption without a value
*
* @return mixed The default value
*/
Expand Down Expand Up @@ -237,7 +240,7 @@ public function equals(InputOption $option)
&& $option->isArray() === $this->isArray()
&& $option->isValueRequired() === $this->isValueRequired()
&& $option->isValueOptional() === $this->isValueOptional()
&& $option->isValueOptionull() === $this->isValueOptionull()
&& $option->isValueTernary() === $this->isValueTernary()
;
}
}
0