8000 minor #26417 [Console] Improved rendering of optional arguments in co… · symfony/symfony@912c7e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 912c7e1

Browse files
committed
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 ------- 938012f [Console] Improved rendering of optional arguments in command synopsis
2 parents a33db13 + 938012f commit 912c7e1

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/Symfony/Component/Console/Input/InputDefinition.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,21 @@ public function getSynopsis($short = false)
382382
$elements[] = '[--]';
383383
}
384384

385+
$tail = '';
385386
foreach ($this->getArguments() as $argument) {
386387
$element = '<'.$argument->getName().'>';
387-
if (!$argument->isRequired()) {
388-
$element = '['.$element.']';
389-
} elseif ($argument->isArray()) {
390-
$element = $element.' ('.$element.')';
391-
}
392-
393388
if ($argument->isArray()) {
394389
$element .= '...';
395390
}
396391

392+
if (!$argument->isRequired()) {
393+
$element = '['.$element;
394+
$tail .= ']';
395+
}
396+
397397
$elements[] = $element;
398398
}
399399

400-
return implode(' ', $elements);
400+
return implode(' ', $elements).$tail;
401401
}
402402
}

src/Symfony/Component/Console/Tests/Input/InputDefinitionTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ public function getGetSynopsisData()
374374

375375
array(new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED))), '<foo>', 'puts arguments in angle brackets'),
376376
array(new InputDefinition(array(new InputArgument('foo'))), '[<foo>]', 'puts optional arguments in square brackets'),
377-
array(new InputDefinition(array(new InputArgument('foo', InputArgument::IS_ARRAY))), '[<foo>]...', 'uses an ellipsis for array arguments'),
378-
array(new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY))), '<foo> (<foo>)...', 'uses parenthesis and ellipsis for required array arguments'),
377+
array(new InputDefinition(array(new InputArgument('foo'), new InputArgument('bar'))), '[<foo> [<bar>]]', 'chains optional arguments inside brackets'),
378+
array(new InputDefinition(array(new InputArgument('foo', InputArgument::IS_ARRAY))), '[<foo>...]', 'uses an ellipsis for array arguments'),
379+
array(new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY))), '<foo>...', 'uses an ellipsis for required array arguments'),
379380

380381
array(new InputDefinition(array(new InputOption('foo'), new InputArgument('foo', InputArgument::REQUIRED))), '[--foo] [--] <foo>', 'puts [--] between options and arguments'),
381382
);

0 commit comments

Comments
 (0)
0