function InputDefinition::getSynopsis
Gets the synopsis.
File
-
vendor/
symfony/ console/ Input/ InputDefinition.php, line 357
Class
- InputDefinition
- A InputDefinition represents a set of valid command line arguments and options.
Namespace
Symfony\Component\Console\InputCode
public function getSynopsis(bool $short = false) : string {
$elements = [];
if ($short && $this->getOptions()) {
$elements[] = '[options]';
}
elseif (!$short) {
foreach ($this->getOptions() as $option) {
$value = '';
if ($option->acceptValue()) {
$value = \sprintf(' %s%s%s', $option->isValueOptional() ? '[' : '', strtoupper($option->getName()), $option->isValueOptional() ? ']' : '');
}
$shortcut = $option->getShortcut() ? \sprintf('-%s|', $option->getShortcut()) : '';
$negation = $option->isNegatable() ? \sprintf('|--no-%s', $option->getName()) : '';
$elements[] = \sprintf('[%s--%s%s%s]', $shortcut, $option->getName(), $value, $negation);
}
}
if (\count($elements) && $this->getArguments()) {
$elements[] = '[--]';
}
$tail = '';
foreach ($this->getArguments() as $argument) {
$element = '<' . $argument->getName() . '>';
if ($argument->isArray()) {
$element .= '...';
}
if (!$argument->isRequired()) {
$element = '[' . $element;
$tail .= ']';
}
$elements[] = $element;
}
return implode(' ', $elements) . $tail;
}