[Console] tweaked previous merge
This commit is contained in:
parent
4f8f2d4f47
commit
61975a1b3d
@ -422,20 +422,11 @@ class InputDefinition
|
|||||||
|
|
||||||
$text = array();
|
$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()) {
|
if ($this->getArguments()) {
|
||||||
$text[] = '<comment>Arguments:</comment>';
|
$text[] = '<comment>Arguments:</comment>';
|
||||||
foreach ($this->getArguments() as $argument) {
|
foreach ($this->getArguments() as $argument) {
|
||||||
if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
|
if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
|
||||||
$default = sprintf('<comment> (default: %s)</comment>', $formatDefault($argument->getDefault()));
|
$default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($argument->getDefault()));
|
||||||
} else {
|
} else {
|
||||||
$default = '';
|
$default = '';
|
||||||
}
|
}
|
||||||
@ -453,7 +444,7 @@ class InputDefinition
|
|||||||
|
|
||||||
foreach ($this->getOptions() as $option) {
|
foreach ($this->getOptions() as $option) {
|
||||||
if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
|
if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
|
||||||
$default = sprintf('<comment> (default: %s)</comment>', $formatDefault($option->getDefault()));
|
$default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($option->getDefault()));
|
||||||
} else {
|
} else {
|
||||||
$default = '';
|
$default = '';
|
||||||
}
|
}
|
||||||
@ -530,4 +521,13 @@ class InputDefinition
|
|||||||
|
|
||||||
return $asDom ? $dom : $dom->saveXml();
|
return $asDom ? $dom : $dom->saveXml();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function formatDefaultValue($default)
|
||||||
|
{
|
||||||
|
if (is_array($default) && $default === array_values($default)) {
|
||||||
|
return sprintf("array('%s')", implode("', '", $default));
|
||||||
|
}
|
||||||
|
|
||||||
|
return str_replace("\n", '', var_export($default, true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ Usage:
|
|||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
command The command to execute
|
command The command to execute
|
||||||
command_name The command name (default: help)
|
command_name The command name (default: 'help')
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--xml To output help as XML
|
--xml To output help as XML
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<comment>Arguments:</comment>
|
<comment>Arguments:</comment>
|
||||||
<info>foo </info> The foo argument
|
<info>foo </info> The foo argument
|
||||||
<info>baz </info> The baz argument<comment> (default: true)</comment>
|
<info>baz </info> The baz argument<comment> (default: true)</comment>
|
||||||
<info>bar </info> The bar argument<comment> (default: array(bar))</comment>
|
<info>bar </info> The bar argument<comment> (default: array('bar'))</comment>
|
||||||
|
|
||||||
<comment>Options:</comment>
|
<comment>Options:</comment>
|
||||||
<info>--foo</info> (-f) The foo option
|
<info>--foo</info> (-f) The foo option
|
||||||
<info>--baz</info> The baz option<comment> (default: false)</comment>
|
<info>--baz</info> The baz option<comment> (default: false)</comment>
|
||||||
<info>--bar</info> (-b) The bar option<comment> (default: bar)</comment>
|
<info>--bar</info> (-b) The bar option<comment> (default: 'bar')</comment>
|
||||||
<info>--qux</info> The qux option<comment> (default: array(bar))</comment><comment> (multiple values allowed)</comment>
|
<info>--qux</info> The qux option<comment> (default: array('foo', 'bar'))</comment><comment> (multiple values allowed)</comment>
|
||||||
<info>--qux2</info> The qux2 option<comment> (default: array ( 'foo' => 'bar',))</comment><comment> (multiple values allowed)</comment>
|
<info>--qux2</info> The qux2 option<comment> (default: array ( 'foo' => 'bar',))</comment><comment> (multiple values allowed)</comment>
|
||||||
|
@ -327,7 +327,7 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
|||||||
new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'),
|
new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'),
|
||||||
new InputOption('baz', null, InputOption::VALUE_OPTIONAL, 'The baz option', false),
|
new InputOption('baz', null, InputOption::VALUE_OPTIONAL, 'The baz option', false),
|
||||||
new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The bar option', 'bar'),
|
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('qux', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The qux option', array('foo', 'bar')),
|
||||||
new InputOption('qux2', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The qux2 option', array('foo' => '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');
|
$this->assertStringEqualsFile(self::$fixtures.'/definition_astext.txt', $definition->asText(), '->asText() returns a textual representation of the InputDefinition');
|
||||||
|
Reference in New Issue
Block a user