Skip to content

Commit

Permalink
[Command] Fix array option parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Herzult committed Jun 7, 2011
1 parent 6737bd3 commit fb051b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Symfony/Component/Console/Input/ArgvInput.php
Expand Up @@ -229,7 +229,13 @@ private function addLongOption($name, $value)
$value = $option->isValueOptional() ? $option->getDefault() : true;
}

$this->options[$name] = $value;
if ($option->isArray() && isset($this->options[$name])) {
$this->options[$name][] = $value;
} else if ($option->isArray()) {
$this->options[$name] = array($value);
} else {
$this->options[$name] = $value;
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/Symfony/Tests/Component/Console/Input/ArgvInputTest.php
Expand Up @@ -147,6 +147,10 @@ public function testParser()
} catch (\RuntimeException $e) {
$this->assertNotEquals('Too many arguments.', $e->getMessage(), '->parse() parses array arguments');
}

$input = new ArgvInput(array('cli.php', '--name=foo', '--name=bar', '--name=baz'));
$input->bind(new InputDefinition(array(new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY))));
$this->assertEquals(array('name' => array('foo', 'bar', 'baz')), $input->getOptions());
}

public function testGetFirstArgument()
Expand Down

0 comments on commit fb051b2

Please sign in to comment.