Flitch\Cli\ArgumentParser::parseShortOption PHP Method

parseShortOption() protected method

Parse a short option.
protected parseShortOption ( string $option, string $argument, array $options, integer &$argumentIndex ) : boolean
$option string
$argument string
$options array
$argumentIndex integer
return boolean
    protected function parseShortOption($option, $argument, array $options, &$argumentIndex)
    {
        $charIndex = 1;
        while ($charIndex !== null) {
            $index = null;
            $char = isset($option[$charIndex]) ? $option[$charIndex] : null;
            if ($char !== null) {
                foreach ($options as $i => $optionData) {
                    if ($char === $optionData['code']) {
                        $index = $i;
                        break;
                    }
                }
            }
            if ($index === null) {
                $this->errors[] = sprintf('Invalid option -- %s', $char);
                return false;
            }
            if (!isset($option[++$charIndex])) {
                $argumentIndex++;
                $charIndex = null;
            }
            if ($options[$index]['has_arg'] !== false && $charIndex !== null && isset($option[$charIndex])) {
                $this->options[] = array('code' => $char, 'argument' => substr($option, $charIndex));
                $argumentIndex++;
                $charIndex = null;
            } elseif ($options[$index]['has_arg'] === true) {
                if (!$argument || !isset($argument[0])) {
                    $this->error = sprintf('Option "%s" requires an argument', $char);
                    return false;
                }
                $this->options[] = array('code' => $char, 'argument' => $argument);
                $argumentIndex++;
                $charIndex = null;
            }
        }
        return true;
    }