Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-empty getArgumentValues array #76

Merged
merged 3 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Commando/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,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);
}

/**
Expand Down
9 changes: 8 additions & 1 deletion tests/Commando/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,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());
}

/**
Expand Down Expand Up @@ -241,4 +248,4 @@ public function testDefineFromSubclass()

$this->assertInstanceOf('Commando\Test\AnotherCommand', $cmd);
}
}
}