From 5bbb67b6fa49fa7ecc0487eabaf6f255d25980a1 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Fri, 31 May 2019 17:38:18 +0100 Subject: [PATCH] Fix #35 - do not load secondary arguments into value of primary --- src/Argument/ArgumentList.php | 13 +++++++++++-- test/unit/Argument/ArgumentListTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Argument/ArgumentList.php b/src/Argument/ArgumentList.php index 7357a00..0001834 100644 --- a/src/Argument/ArgumentList.php +++ b/src/Argument/ArgumentList.php @@ -67,9 +67,18 @@ protected function buildArgumentList(array $arguments):void { ); } else { - $skipNextArgument = true; $name = $arg; - $value = $arguments[$i + 1] ?? null; + + $nextArgument = $arguments[$i + 1] ?? null; + + if($nextArgument + && strpos($nextArgument, "-") !== 0) { + $value = $arguments[$i + 1]; + $skipNextArgument = true; + } + else { + $value = null; + } } if ($arg[1] === "-") { diff --git a/test/unit/Argument/ArgumentListTest.php b/test/unit/Argument/ArgumentListTest.php index e78b645..cca46e5 100644 --- a/test/unit/Argument/ArgumentListTest.php +++ b/test/unit/Argument/ArgumentListTest.php @@ -303,6 +303,31 @@ public function testGetValueParameterWithShortOption(string...$args) { self::assertEquals($args[2], $value); } + public function testGetValueForParameterForMultiple() { + $argumentList = new ArgumentList( + "test-script", + "test-command", + "--one", + "--two", + "--three", + "--four" + ); + + $param1 = self::createMock(Parameter::class); + $param1->method("getLongOption")->willReturn("one"); + $param2 = self::createMock(Parameter::class); + $param2->method("getLongOption")->willReturn("two"); + $param3 = self::createMock(Parameter::class); + $param3->method("getLongOption")->willReturn("three"); + $param4 = self::createMock(Parameter::class); + $param4->method("getLongOption")->willReturn("four"); + + self::assertTrue($argumentList->contains($param1)); + self::assertTrue($argumentList->contains($param2)); + self::assertTrue($argumentList->contains($param3)); + self::assertTrue($argumentList->contains($param4)); + } + public function data_randomNamedArgs():array { $dataSet = [];