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

Breadcrumb

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

function Command::addOption

Adds an option.

Parameters

$shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts:

$mode The option mode: One of the InputOption::VALUE_* constants:

$default The default value (must be null for InputOption::VALUE_NONE):

array|\Closure(CompletionInput,CompletionSuggestions):list<string|Suggestion> $suggestedValues The values used for input completion:

Return value

$this

Throws

InvalidArgumentException If option mode is invalid or incompatible

2 methods override Command::addOption()
LazyCommand::addOption in vendor/symfony/console/Command/LazyCommand.php
TraceableCommand::addOption in vendor/symfony/console/Command/TraceableCommand.php
Adds an option.

File

vendor/symfony/console/Command/Command.php, line 432

Class

Command
Base class for all commands.

Namespace

Symfony\Component\Console\Command

Code

public function addOption(string $name, string|array|null $shortcut = null, ?int $mode = null, string $description = '', mixed $default = null, array|\Closure $suggestedValues = []) : static {
    $this->definition
        ->addOption(new InputOption($name, $shortcut, $mode, $description, $default, $suggestedValues));
    $this->fullDefinition?->addOption(new InputOption($name, $shortcut, $mode, $description, $default, $suggestedValues));
    return $this;
}

API Navigation

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