From 345d714e54fd20a726d8ff6cfed1218f870682e7 Mon Sep 17 00:00:00 2001 From: Pipe Gutierrez Date: Sat, 5 Aug 2017 17:15:38 -0500 Subject: [PATCH 1/2] Adds test checking if argumentValues are empty --- tests/Commando/CommandTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/Commando/CommandTest.php b/tests/Commando/CommandTest.php index 40a05c1..e84de65 100755 --- a/tests/Commando/CommandTest.php +++ b/tests/Commando/CommandTest.php @@ -174,6 +174,13 @@ public function testGetValues() $this->assertEquals(array('v3', 'v4', 'v5'), $cmd->getArgumentValues()); $this->assertEquals(array('a' => 'v1', 'b' => 'v2'), $cmd->getFlagValues()); + + $tokens = array('filename'); + $cmd = new Command($tokens); + $cmd + ->argument(); + + $this->assertEmpty($cmd->getArgumentValues()); } /** @@ -206,4 +213,4 @@ public function testRequirementsOnOptionsMissing() ->needs('b'); } -} \ No newline at end of file +} From fb9fb17751d86b05a12a110c8c12c6497a2fc4d2 Mon Sep 17 00:00:00 2001 From: Pipe Gutierrez Date: Sat, 5 Aug 2017 17:22:43 -0500 Subject: [PATCH 2/2] Filters out empty value arguments --- src/Commando/Command.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Commando/Command.php b/src/Commando/Command.php index bcf2ebb..915a3ba 100755 --- a/src/Commando/Command.php +++ b/src/Commando/Command.php @@ -640,9 +640,17 @@ public function getFlags() public function getArgumentValues() { $this->parseIfNotParsed(); + + $arguments = $this->arguments; + $arguments = array_filter($arguments, function(Option $argument){ + $argumentValue = $argument->getValue(); + return isset($argumentValue); + }); + + return array_map(function(Option $argument) { return $argument->getValue(); - }, $this->arguments); + }, $arguments); } /**