8000 [Console] Improved rendering of optional arguments in command synopsis · symfony/symfony@938012f · GitHub
[go: up one dir, main page]

Skip to content

Commit 938012f

Browse files
AnrDaemonfabpot
authored andcommitted
[Console] Improved rendering of optional arguments in command synopsis
1 parent d79c528 commit 938012f

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