Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WIP]REFS #10487 - [Console] Fixed Options arguments behaviour #10603

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ protected function getDefaultInputDefinition()

new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_OPTIONAL, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version.'),
new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output.'),
new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output.'),
Expand Down
20 changes: 11 additions & 9 deletions src/Symfony/Component/Console/Input/ArgvInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,16 @@ private function addLongOption($name, $value)
if (null === $value && $option->acceptValue() && count($this->parsed)) {
// if option accepts an optional or mandatory argument
// let's see if there is one provided
$next = array_shift($this->parsed);
if (isset($next[0]) && '-' !== $next[0]) {
$value = $next;
} elseif (empty($next)) {
$value = '';
} else {
array_unshift($this->parsed, $next);
}
/* [This code should not be used]
$next = array_shift($this->parsed);
if (isset($next[0]) && '-' !== $next[0]) {
$value = $next;
} elseif (empty($next)) {
$value = '';
} else {
array_unshift($this->parsed, $next);
}
*/
}

if (null === $value) {
Expand Down Expand Up @@ -313,7 +315,7 @@ public function getParameterOption($values, $default = false)
$tokens = $this->tokens;
while ($token = array_shift($tokens)) {
foreach ($values as $value) {
if ($token === $value || 0 === strpos($token, $value.'=')) {
if (substr($token, 0, strpos($token, '=')) === $value || 0 === strpos($token, $value.'=')) {
if (false !== $pos = strpos($token, '=')) {
return substr($token, $pos + 1);
}
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,20 @@ public function testVerboseValueNotBreakArguments()
$application->run($input, $output);
}

public function testVerboseLongValueInArgv()
{
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->add(new \FooCommand());

$output = new StreamOutput(fopen('php://memory', 'w', false));

$input = new ArgvInput(array('cli.php', '--verbose=3', 'foo:bar'));
$application->run($input, $output);
$this->assertEquals(Output::VERBOSITY_DEBUG, $output->getVerbosity());
}

public function testRunReturnsIntegerExitCode()
{
$exception = new \Exception('', 4);
Expand Down