diff --git a/src/Illuminate/Console/Parser.php b/src/Illuminate/Console/Parser.php index 4ccc88dc3ea5..5c1e92fcf6d0 100644 --- a/src/Illuminate/Console/Parser.php +++ b/src/Illuminate/Console/Parser.php @@ -89,6 +89,8 @@ protected static function parseArgument($token) return new InputArgument(trim($token, '*'), InputArgument::IS_ARRAY | InputArgument::REQUIRED, $description); case Str::endsWith($token, '?'): return new InputArgument(trim($token, '?'), InputArgument::OPTIONAL, $description); + case preg_match('/(.+)\=\*(.+)/', $token, $matches): + return new InputArgument($matches[1], InputArgument::IS_ARRAY, $description, preg_split('/,\s?/', $matches[2])); case preg_match('/(.+)\=(.+)/', $token, $matches): return new InputArgument($matches[1], InputArgument::OPTIONAL, $description, $matches[2]); default: @@ -120,6 +122,8 @@ protected static function parseOption($token) return new InputOption(trim($token, '='), $shortcut, InputOption::VALUE_OPTIONAL, $description); case Str::endsWith($token, '=*'): return new InputOption(trim($token, '=*'), $shortcut, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $description); + case preg_match('/(.+)\=\*(.+)/', $token, $matches): + return new InputOption($matches[1], $shortcut, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $description, preg_split('/,\s?/', $matches[2])); case preg_match('/(.+)\=(.+)/', $token, $matches): return new InputOption($matches[1], $shortcut, InputOption::VALUE_OPTIONAL, $description, $matches[2]); default: diff --git a/tests/Console/ConsoleParserTest.php b/tests/Console/ConsoleParserTest.php index 0ca31752f1e1..fec0c3015aca 100644 --- a/tests/Console/ConsoleParserTest.php +++ b/tests/Console/ConsoleParserTest.php @@ -107,4 +107,23 @@ public function testShortcutNameParsing() $this->assertTrue($results[2][0]->acceptValue()); $this->assertTrue($results[2][0]->isArray()); } + + public function testDefaultValueParsing() + { + $results = Parser::parse('command:name {argument=defaultArgumentValue} {--option=defaultOptionValue}'); + + $this->assertFalse($results[1][0]->isRequired()); + $this->assertEquals('defaultArgumentValue', $results[1][0]->getDefault()); + $this->assertTrue($results[2][0]->acceptValue()); + $this->assertEquals('defaultOptionValue', $results[2][0]->getDefault()); + + $results = Parser::parse('command:name {argument=*defaultArgumentValue1,defaultArgumentValue2} {--option=*defaultOptionValue1,defaultOptionValue2}'); + + $this->assertTrue($results[1][0]->isArray()); + $this->assertFalse($results[1][0]->isRequired()); + $this->assertEquals(['defaultArgumentValue1', 'defaultArgumentValue2'], $results[1][0]->getDefault()); + $this->assertTrue($results[2][0]->acceptValue()); + $this->assertTrue($results[2][0]->isArray()); + $this->assertEquals(['defaultOptionValue1', 'defaultOptionValue2'], $results[2][0]->getDefault()); + } }