Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fixed array input parsing in ArgvInput #110

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

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 14 additions & 3 deletions 17 src/Symfony/Component/Console/Input/ArgvInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,22 @@ protected function parseLongOption($token)
*/
protected function parseArgument($token)
{
if (!$this->definition->hasArgument(count($this->arguments))) {
$c = count($this->arguments);

// if input is expecting another argument, add it
if ($this->definition->hasArgument($c)) {
$arg = $this->definition->getArgument($c);
$this->arguments[$arg->getName()] = $arg->isArray()? array($token) : $token;

// if last argument isArray(), append token to last argument
} elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) {
$arg = $this->definition->getArgument($c - 1);
$this->arguments[$arg->getName()][] = $token;

// unexpected argument
} else {
throw new \RuntimeException('Too many arguments.');
}

$this->arguments[$this->definition->getArgument(count($this->arguments))->getName()] = $token;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions 8 tests/Symfony/Tests/Component/Console/Input/ArgvInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ public function testParser()
$input = new TestInput(array('cli.php', '-fbbar'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL))));
$this->assertEquals(array('foo' => 'bbar', 'bar' => null), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and one of them takes a value');

try {
$input = new TestInput(array('cli.php', 'foo', 'bar', 'baz', 'bat'));
$input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::IS_ARRAY))));
$this->assertEquals(array('name' => array('foo', 'bar', 'baz', 'bat')), $input->getArguments(), '->parse() parses array arguments');
} catch (\RuntimeException $e) {
$this->assertNotEquals('Too many arguments.', $e->getMessage(), '->parse() parses array arguments');
}
}

public function testGetFirstArgument()
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.