Skip to content

Commit 8727481

Browse files
authored
Fixed bug that the command description will cause parse error when contains --. (#6586)
1 parent 17132fe commit 8727481

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected static function parameters(array $tokens): array
6060
$options = [];
6161

6262
foreach ($tokens as $token) {
63-
if (preg_match('/-{2,}(.*)/', $token, $matches)) {
63+
if (preg_match('/^-{2,}(.*)/', $token, $matches)) {
6464
$options[] = static::parseOption($matches[1]);
6565
} else {
6666
$arguments[] = static::parseArgument($token);

tests/CommandParserTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ public function testBasicParameterParsing()
8080
$this->assertSame('The option description.', $results[2][0]->getDescription());
8181
$this->assertTrue($results[2][0]->acceptValue());
8282
$this->assertTrue($results[2][0]->isArray());
83+
84+
$results = Parser::parse('command:name
85+
{argument?* : The argument description --json.}
86+
{--option=* : The option description --json.}');
87+
88+
$this->assertSame('command:name', $results[0]);
89+
$this->assertSame('argument', $results[1][0]->getName());
90+
$this->assertSame('The argument description --json.', $results[1][0]->getDescription());
91+
$this->assertTrue($results[1][0]->isArray());
92+
$this->assertFalse($results[1][0]->isRequired());
93+
$this->assertSame('option', $results[2][0]->getName());
94+
$this->assertSame('The option description --json.', $results[2][0]->getDescription());
95+
$this->assertTrue($results[2][0]->acceptValue());
96+
$this->assertTrue($results[2][0]->isArray());
8397
}
8498

8599
public function testShortcutNameParsing()

0 commit comments

Comments
 (0)