minor #26417 [Console] Improved rendering of optional arguments in command synopsis (AnrDaemon)
This PR was squashed before being merged into the 4.1-dev branch (closes #26417).
Discussion
----------
[Console] Improved rendering of optional arguments in command synopsis
Current rendering:
```
build [options] [--] [<file>] [<output-dir>] [<packages>]...
```
Fixed (and actually correct) rendering:
```
build [options] [--] [<file> [<output-dir> [<packages>...]]]
```
Also dropped duplicating required array-type argument. There's just no need for that, it only confuses the reader.
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes and no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | --
| License | MIT
| Doc PR | --
Optional arguments can not be independent, in general. Neither the argument parser allows that.
Commits
-------
938012f0ea
[Console] Improved rendering of optional arguments in command synopsis
This commit is contained in:
commit
912c7e12f1
@ -382,21 +382,21 @@ class InputDefinition
|
|||||||
$elements[] = '[--]';
|
$elements[] = '[--]';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$tail = '';
|
||||||
foreach ($this->getArguments() as $argument) {
|
foreach ($this->getArguments() as $argument) {
|
||||||
$element = '<'.$argument->getName().'>';
|
$element = '<'.$argument->getName().'>';
|
||||||
if (!$argument->isRequired()) {
|
|
||||||
$element = '['.$element.']';
|
|
||||||
} elseif ($argument->isArray()) {
|
|
||||||
$element = $element.' ('.$element.')';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($argument->isArray()) {
|
if ($argument->isArray()) {
|
||||||
$element .= '...';
|
$element .= '...';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$argument->isRequired()) {
|
||||||
|
$element = '['.$element;
|
||||||
|
$tail .= ']';
|
||||||
|
}
|
||||||
|
|
||||||
$elements[] = $element;
|
$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', 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'))), '[<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'), new InputArgument('bar'))), '[<foo> [<bar>]]', 'chains optional arguments inside brackets'),
|
||||||
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', 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'),
|
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