From 44971faa2155a199ad366a5e953db2a5da3b15b9 Mon Sep 17 00:00:00 2001 From: mickaelandrieu Date: Tue, 1 Apr 2014 11:09:29 +0200 Subject: [PATCH] [WIP]REFS #10487 - [Console] Fixed Options arguments behaviour --- src/Symfony/Component/Console/Application.php | 2 +- .../Component/Console/Input/ArgvInput.php | 20 ++++++++++--------- .../Console/Tests/ApplicationTest.php | 14 +++++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 44b8a9393b7be..4c36a9dde4bc0 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -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.'), diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 0d6b3276294ee..198fc017cca28 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -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) { @@ -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); } diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index adbf8630a3ae6..4c797c0a6522b 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -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);