Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. InputDefinition.php

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\Input

Code

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;
}
RSS feed
Powered by Drupal