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

Breadcrumb

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

function ArgvInput::parseArgument

Parses an argument.

Throws

RuntimeException When too many arguments are given

1 call to ArgvInput::parseArgument()
ArgvInput::parseToken in vendor/symfony/console/Input/ArgvInput.php

File

vendor/symfony/console/Input/ArgvInput.php, line 164

Class

ArgvInput
ArgvInput represents an input coming from the CLI arguments.

Namespace

Symfony\Component\Console\Input

Code

private function parseArgument(string $token) : void {
    $c = \count($this->arguments);
    // if input is expecting another argument, add it
    if ($this->definition
        ->hasArgument($c)) {
        $arg = $this->definition
            ->getArgument($c);
        $this->arguments[$arg->getName()] = $arg->isArray() ? [
            $token,
        ] : $token;
        // if last argument isArray(), append token to last argument
    }
    elseif ($this->definition
        ->hasArgument($c - 1) && $this->definition
        ->getArgument($c - 1)
        ->isArray()) {
        $arg = $this->definition
            ->getArgument($c - 1);
        $this->arguments[$arg->getName()][] = $token;
        // unexpected argument
    }
    else {
        $all = $this->definition
            ->getArguments();
        $symfonyCommandName = null;
        if (($inputArgument = $all[$key = array_key_first($all)] ?? null) && 'command' === $inputArgument->getName()) {
            $symfonyCommandName = $this->arguments['command'] ?? null;
            unset($all[$key]);
        }
        if (\count($all)) {
            if ($symfonyCommandName) {
                $message = \sprintf('Too many arguments to "%s" command, expected arguments "%s".', $symfonyCommandName, implode('" "', array_keys($all)));
            }
            else {
                $message = \sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all)));
            }
        }
        elseif ($symfonyCommandName) {
            $message = \sprintf('No arguments expected for "%s" command, got "%s".', $symfonyCommandName, $token);
        }
        else {
            $message = \sprintf('No arguments expected, got "%s".', $token);
        }
        throw new RuntimeException($message);
    }
}

API Navigation

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