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

Breadcrumb

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

function CompletionInput::bind

Overrides Input::bind

File

vendor/symfony/console/Completion/CompletionInput.php, line 67

Class

CompletionInput
An input specialized for shell completion.

Namespace

Symfony\Component\Console\Completion

Code

public function bind(InputDefinition $definition) : void {
    parent::bind($definition);
    $relevantToken = $this->getRelevantToken();
    if ('-' === $relevantToken[0]) {
        // the current token is an input option: complete either option name or option value
        [
            $optionToken,
            $optionValue,
        ] = explode('=', $relevantToken, 2) + [
            '',
            '',
        ];
        $option = $this->getOptionFromToken($optionToken);
        if (null === $option && !$this->isCursorFree()) {
            $this->completionType = self::TYPE_OPTION_NAME;
            $this->completionValue = $relevantToken;
            return;
        }
        if ($option?->acceptValue()) {
            $this->completionType = self::TYPE_OPTION_VALUE;
            $this->completionName = $option->getName();
            $this->completionValue = $optionValue ?: (!str_starts_with($optionToken, '--') ? substr($optionToken, 2) : '');
            return;
        }
    }
    $previousToken = $this->tokens[$this->currentIndex - 1];
    if ('-' === $previousToken[0] && '' !== trim($previousToken, '-')) {
        // check if previous option accepted a value
        $previousOption = $this->getOptionFromToken($previousToken);
        if ($previousOption?->acceptValue()) {
            $this->completionType = self::TYPE_OPTION_VALUE;
            $this->completionName = $previousOption->getName();
            $this->completionValue = $relevantToken;
            return;
        }
    }
    // complete argument value
    $this->completionType = self::TYPE_ARGUMENT_VALUE;
    foreach ($this->definition
        ->getArguments() as $argumentName => $argument) {
        if (!isset($this->arguments[$argumentName])) {
            break;
        }
        $argumentValue = $this->arguments[$argumentName];
        $this->completionName = $argumentName;
        if (\is_array($argumentValue)) {
            $this->completionValue = $argumentValue ? $argumentValue[array_key_last($argumentValue)] : null;
        }
        else {
            $this->completionValue = $argumentValue;
        }
    }
    if ($this->currentIndex >= \count($this->tokens)) {
        if (!isset($this->arguments[$argumentName]) || $this->definition
            ->getArgument($argumentName)
            ->isArray()) {
            $this->completionName = $argumentName;
        }
        else {
            // we've reached the end
            $this->completionType = self::TYPE_NONE;
            $this->completionName = null;
        }
        $this->completionValue = '';
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal