private function processToken() { $optionFound = null; if (($optionName = $this->token->afterStarts(Runner::OPTION_NAME)) && isset($this->def->byName[$optionName])) { $optionFound = $this->def->byName[$optionName]; } elseif (($optionName = $this->token->afterStarts(Runner::OPTION_SHORT)) && isset($this->def->byShortName[$optionName])) { $optionFound = $this->def->byShortName[$optionName]; } if ($this->variadicStarted && $optionFound) { if (empty($this->variadicValues)) { throw new Exception('Unexpected option, value required', Exception::VALUE_REQUIRED); } $this->finishVariadic(); } if (!empty($this->def->requiredArguments) && $optionFound) { throw new Exception('Unexpected option, argument required', Exception::ARGUMENT_REQUIRED); } if ($this->variadicStarted) { $this->continueVariadic(); return; } if ($this->valueRequired) { if ($optionFound) { throw new Exception('Unexpected option, value required', Exception::VALUE_REQUIRED); } $this->valueRequired(); return; } if (!empty($this->def->requiredArguments)) { $this->option = array_shift($this->def->requiredArguments); $this->processOption(); return; } if ($optionFound) { $this->option = $optionFound; $this->processOption(); return; } if ($this->def->optionalArguments) { $this->option = array_shift($this->def->optionalArguments); $this->processOption(); return; } throw new CliException('Unexpected token: ' . $this->token, CliException::UNKNOWN_OPTION); }