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

Breadcrumb

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

function Parser::parseShortOption

Throws

RequiredOptionArgumentMissingException

1 call to Parser::parseShortOption()
Parser::parse in vendor/sebastian/cli-parser/src/Parser.php
@psalm-param list<string> $argv @psalm-param list<string> $longOptions

File

vendor/sebastian/cli-parser/src/Parser.php, line 116

Class

Parser

Namespace

SebastianBergmann\CliParser

Code

private function parseShortOption(string $argument, string $shortOptions, array &$options, array &$argv) : void {
    $argumentLength = strlen($argument);
    for ($i = 0; $i < $argumentLength; $i++) {
        $option = $argument[$i];
        $optionArgument = null;
        if ($argument[$i] === ':' || ($spec = strstr($shortOptions, $option)) === false) {
            throw new UnknownOptionException('-' . $option);
        }
        if (strlen($spec) > 1 && $spec[1] === ':') {
            if ($i + 1 < $argumentLength) {
                $options[] = [
                    $option,
                    substr($argument, $i + 1),
                ];
                break;
            }
            if (!(strlen($spec) > 2 && $spec[2] === ':')) {
                $optionArgument = current($argv);
                if (!$optionArgument) {
                    throw new RequiredOptionArgumentMissingException('-' . $option);
                }
                assert(is_string($optionArgument));
                next($argv);
            }
        }
        $options[] = [
            $option,
            $optionArgument,
        ];
    }
}

API Navigation

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