diff --git a/src/Symfony/Component/Console/Input/InputDefinition.php b/src/Symfony/Component/Console/Input/InputDefinition.php
index a7c20ac99a..efe7cd3de1 100644
--- a/src/Symfony/Component/Console/Input/InputDefinition.php
+++ b/src/Symfony/Component/Console/Input/InputDefinition.php
@@ -422,11 +422,20 @@ class InputDefinition
$text = array();
+ $formatDefault = function ($default) {
+ if (is_array($default) && $default === array_values($default)) {
+ $default = 'array('.implode(', ', $default).')';
+ } elseif (is_bool($default) || is_array($default)) {
+ $default = str_replace("\n", '', var_export($default, true));
+ }
+ return $default;
+ };
+
if ($this->getArguments()) {
$text[] = 'Arguments:';
foreach ($this->getArguments() as $argument) {
if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
- $default = sprintf(' (default: %s)', is_bool($argument->getDefault()) || is_array($argument->getDefault()) ? str_replace("\n", '', var_export($argument->getDefault(), true)): $argument->getDefault());
+ $default = sprintf(' (default: %s)', $formatDefault($argument->getDefault()));
} else {
$default = '';
}
@@ -444,7 +453,7 @@ class InputDefinition
foreach ($this->getOptions() as $option) {
if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
- $default = sprintf(' (default: %s)', is_bool($option->getDefault()) || is_array($option->getDefault()) ? str_replace("\n", '', var_export($option->getDefault(), true)): $option->getDefault());
+ $default = sprintf(' (default: %s)', $formatDefault($option->getDefault()));
} else {
$default = '';
}
diff --git a/tests/Symfony/Tests/Component/Console/Fixtures/definition_astext.txt b/tests/Symfony/Tests/Component/Console/Fixtures/definition_astext.txt
index b20fc1bf32..3f6525ff83 100644
--- a/tests/Symfony/Tests/Component/Console/Fixtures/definition_astext.txt
+++ b/tests/Symfony/Tests/Component/Console/Fixtures/definition_astext.txt
@@ -1,9 +1,11 @@
Arguments:
foo The foo argument
baz The baz argument (default: true)
- bar The bar argument (default: array ( 0 => 'bar',))
+ bar The bar argument (default: array(bar))
Options:
--foo (-f) The foo option
--baz The baz option (default: false)
--bar (-b) The bar option (default: bar)
+ --qux The qux option (default: array(bar)) (multiple values allowed)
+ --qux2 The qux2 option (default: array ( 'foo' => 'bar',)) (multiple values allowed)
diff --git a/tests/Symfony/Tests/Component/Console/Input/InputDefinitionTest.php b/tests/Symfony/Tests/Component/Console/Input/InputDefinitionTest.php
index a119b8bc8a..f374ac5d65 100644
--- a/tests/Symfony/Tests/Component/Console/Input/InputDefinitionTest.php
+++ b/tests/Symfony/Tests/Component/Console/Input/InputDefinitionTest.php
@@ -327,6 +327,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'),
new InputOption('baz', null, InputOption::VALUE_OPTIONAL, 'The baz option', false),
new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The bar option', 'bar'),
+ new InputOption('qux', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The qux option', array('bar')),
+ new InputOption('qux2', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The qux2 option', array('foo' => 'bar')),
));
$this->assertStringEqualsFile(self::$fixtures.'/definition_astext.txt', $definition->asText(), '->asText() returns a textual representation of the InputDefinition');
}