[Console] Improved rendering of optional arguments in command synopsis
This commit is contained in:
parent
d79c528b40
commit
938012f0ea
@ -382,21 +382,21 @@ class InputDefinition
|
||||
$elements[] = '[--]';
|
||||
}
|
||||
|
||||
$tail = '';
|
||||
foreach ($this->getArguments() as $argument) {
|
||||
$element = '<'.$argument->getName().'>';
|
||||
if (!$argument->isRequired()) {
|
||||
$element = '['.$element.']';
|
||||
} elseif ($argument->isArray()) {
|
||||
$element = $element.' ('.$element.')';
|
||||
}
|
||||
|
||||
if ($argument->isArray()) {
|
||||
$element .= '...';
|
||||
}
|
||||
|
||||
if (!$argument->isRequired()) {
|
||||
$element = '['.$element;
|
||||
$tail .= ']';
|
||||
}
|
||||
|
||||
$elements[] = $element;
|
||||
}
|
||||
|
||||
return implode(' ', $elements);
|
||||
return implode(' ', $elements).$tail;
|
||||
}
|
||||
}
|
||||
|
@ -374,8 +374,9 @@ class InputDefinitionTest extends TestCase
|
||||
|
||||
array(new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED))), '<foo>', 'puts arguments in angle brackets'),
|
||||
array(new InputDefinition(array(new InputArgument('foo'))), '[<foo>]', 'puts optional arguments in square brackets'),
|
||||
array(new InputDefinition(array(new InputArgument('foo', InputArgument::IS_ARRAY))), '[<foo>]...', 'uses an ellipsis for array arguments'),
|
||||
array(new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY))), '<foo> (<foo>)...', 'uses parenthesis and ellipsis for required array arguments'),
|
||||
array(new InputDefinition(array(new InputArgument('foo'), new InputArgument('bar'))), '[<foo> [<bar>]]', 'chains optional arguments inside brackets'),
|
||||
array(new InputDefinition(array(new InputArgument('foo', InputArgument::IS_ARRAY))), '[<foo>...]', 'uses an ellipsis for array arguments'),
|
||||
array(new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY))), '<foo>...', 'uses an ellipsis for required array arguments'),
|
||||
|
||||
array(new InputDefinition(array(new InputOption('foo'), new InputArgument('foo', InputArgument::REQUIRED))), '[--foo] [--] <foo>', 'puts [--] between options and arguments'),
|
||||
);
|
||||
|
Reference in New Issue
Block a user