function ArgvInput::addLongOption
Adds a long option value.
Throws
RuntimeException When option given doesn't exist
3 calls to ArgvInput::addLongOption()
- ArgvInput::addShortOption in vendor/
symfony/ console/ Input/ ArgvInput.php - Adds a short option value.
- ArgvInput::parseLongOption in vendor/
symfony/ console/ Input/ ArgvInput.php - Parses a long option.
- ArgvInput::parseShortOptionSet in vendor/
symfony/ console/ Input/ ArgvInput.php - Parses a short option set.
File
-
vendor/
symfony/ console/ Input/ ArgvInput.php, line 222
Class
- ArgvInput
- ArgvInput represents an input coming from the CLI arguments.
Namespace
Symfony\Component\Console\InputCode
private function addLongOption(string $name, mixed $value) : void {
if (!$this->definition
->hasOption($name)) {
if (!$this->definition
->hasNegation($name)) {
throw new RuntimeException(\sprintf('The "--%s" option does not exist.', $name));
}
$optionName = $this->definition
->negationToName($name);
if (null !== $value) {
throw new RuntimeException(\sprintf('The "--%s" option does not accept a value.', $name));
}
$this->options[$optionName] = false;
return;
}
$option = $this->definition
->getOption($name);
if (null !== $value && !$option->acceptValue()) {
throw new RuntimeException(\sprintf('The "--%s" option does not accept a value.', $name));
}
if (\in_array($value, [
'',
null,
], true) && $option->acceptValue() && \count($this->parsed)) {
// if option accepts an optional or mandatory argument
// let's see if there is one provided
$next = array_shift($this->parsed);
if (isset($next[0]) && '-' !== $next[0] || \in_array($next, [
'',
null,
], true)) {
$value = $next;
}
else {
array_unshift($this->parsed, $next);
}
}
if (null === $value) {
if ($option->isValueRequired()) {
throw new RuntimeException(\sprintf('The "--%s" option requires a value.', $name));
}
if (!$option->isArray() && !$option->isValueOptional()) {
$value = true;
}
}
if ($option->isArray()) {
$this->options[$name][] = $value;
}
else {
$this->options[$name] = $value;
}
}