Add default options.

@param \Symfony\Component\Console\Command\Command $command
Command object.

@hook option
519187
public function defaultOptions(Command $command) {
    $command->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Configuration file to be used instead of default `robo.yml.dist`.', 'robo.yml');
    $command->addOption('override', 'o', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Configuration value(s) to be overridden. Format: "path.to.key:value"', []);
  }
116342
protected function _buildArgs($controller, $command)
    {
        $args = [];

        $di = $this->_di;

        $parameters = (new \ReflectionMethod($controller, $command . 'Command'))->getParameters();
        $shortNames = $this->_getShortNames($parameters);

        foreach ($parameters as $parameter) {
            $name = $parameter->getName();
            $value = null;

            $type = $parameter->getClass();
            if ($type !== null) {
                $type = $type->getName();
            } elseif ($parameter->isDefaultValueAvailable()) {
                $type = gettype($parameter->getDefaultValue());
            }

            if ($className = ($c = $parameter->getClass()) ? $c->getName() : null) {
                if ($di->has($name)) {
                    $value = $di->get($name);
                } elseif ($di->has($className)) {
                    $value = $di->get($className);
                } else {
                    $value = $di->getShared($className);
                }
            } elseif ($this->arguments->hasOption($name)) {
                $value = $this->arguments->getOption($name);
            } elseif (isset($shortNames[$name]) && $this->arguments->hasOption($shortNames[$name])) {
                $value = $this->arguments->getOption($shortNames[$name]);
            } elseif (count($this->arguments->getValues()) === 1) {
                $value = $this->arguments->getValues()[0];
            } elseif ($parameter->isDefaultValueAvailable()) {
                $value = $parameter->getDefaultValue();
            } else {
                $this->arguments->getOption($name . (isset($shortNames[$name]) ? ":$shortNames[$name]" : ''));
            }

            switch ($type) {
                case 'boolean':
                    $value = (bool)$value;
                    break;
                case 'integer':
                    $value = (int)$value;
                    break;
                case 'double':
                    $value = (float)$value;
                    break;
                case 'string':
                    $value = (string)$value;
                    break;
                case 'array':
                    $value = is_string($value) ? explode(',', $value) : (array)$value;
                    break;
            }

            if ($parameter->isArray()) {
                $args[] = (array)$value;
            } else {
                $args[] = $value;
            }
        }

        return $args;
    }
971524
protected function fixCommandDefinition(BaseCommand $command)
    {
        $definition = $command->getDefinition();

        if (!$definition->hasOption('verbose')) {
            $definition->addOption(
                new InputOption(
                    'verbose',
                    'v|vv|vvv',
                    InputOption::VALUE_NONE,
                    'Shows more details including new commits pulled in when updating packages.'
                )
            );
        }
        if (!$definition->hasOption('profile')) {
            $definition->addOption(
                new InputOption(
                    'profile',
                    null,
                    InputOption::VALUE_NONE,
                    'Display timing and memory usage information'
                )
            );
        }
        if (!$definition->hasOption('no-plugins')) {
            $definition->addOption(
                new InputOption(
                    'no-plugins',
                    null,
                    InputOption::VALUE_NONE,
                    'Whether to disable plugins.'
                )
            );
        }
        if (!$definition->hasOption('working-dir')) {
            $definition->addOption(
                new InputOption(
                    'working-dir',
                    '-d',
                    InputOption::VALUE_REQUIRED,
                    'If specified, use the given directory as working directory.'
                )
            );
        }
    }
152955
protected function addConsoleCommand(Command $command)
    {
        Deprecated::method(3.0, 'registerNutCommands');

        $app = $this->getContainer();
        $app['nut.commands.add']($command);
    }
530396
public function fire(Command $command)
    {
        if ($command->option('verbose')) {
            $command->call('key:generate');
            $command->call('api:key-generate');

            return;
        }
        $command->callSilent('key:generate');
        $command->callSilent('api:key-generate');
    }
1036292
public function add(SymfonyCommand $command)
	{
		if ($command instanceof Command)
		{
			$command->setFlyphp($this->flyphp);
		}

		return $this->addToParent($command);
	}
517857
protected function compileOptions(ICommand $command, IRequest $request)
    {
        foreach ($command->getOptions() as $option) {
            $shortNameIsSet = $option->getShortName() === null ?
                    false :
                    $request->optionIsSet($option->getShortName());
            $longNameIsSet = $request->optionIsSet($option->getName());

            // All options are optional (duh)
            if ($shortNameIsSet || $longNameIsSet) {
                if ($longNameIsSet) {
                    $value = $request->getOptionValue($option->getName());
                } else {
                    $value = $request->getOptionValue($option->getShortName());
                }

                if (!$option->valueIsPermitted() && $value !== null) {
                    throw new RuntimeException("Option \"{$option->getName()}\" does not permit a value");
                }

                if ($option->valueIsRequired() && $value === null) {
                    throw new RuntimeException("Option \"{$option->getName()}\" requires a value");
                }

                if ($option->valueIsOptional() && $value === null) {
                    $value = $option->getDefaultValue();
                }

                $command->setOptionValue($option->getName(), $value);
            } elseif ($option->valueIsPermitted()) {
                // Set the value for the option to its default value, if values are permitted
                $command->setOptionValue($option->getName(), $option->getDefaultValue());
            }
        }
    }
910476
public function setCommand($command): void
    {
        $this->log(
            "The command attribute is deprecated.\nPlease use the executable attribute and nested arg elements.",
            Project::MSG_WARN
        );
        $this->commandline = new Commandline($command);
        $this->executable = $this->commandline->getExecutable();
    }
996654
protected void addDefaultCommands(Bootstrap<T> bootstrap) {
        bootstrap.addCommand(new ServerCommand<>(this));
        bootstrap.addCommand(new CheckCommand<>(this));
    }
642898
public function addCommand(Command $command) {
        $this->commands[$command->getName()] = $command;
        $command->freeze();
        return $this;
    }
1295064
public function command($command)
    {
        if (! $command instanceof Command) {
            $command = $this[$command];
        }

        $this['console']->add($command);
    }
335587
public function execute($command, $arguments = array())
    {
        $options = $this->getOptions();
        $consoleDir = $this->getConsoleDir();

        if (null === $consoleDir) {
            return;
        }

        $argumentString = '';

        foreach ($arguments as $argument) {
            $argumentString .= escapeshellarg($argument) . ' ';
        }

        $this->executeCommand($consoleDir, $command . ' ' . $argumentString);
    }
344
public function add($command)
    {
        $tasks = $this->prepper
                    ->load(get_class($command))
                    ->describe();

        $this->library->add(['task' => $tasks, 'class' => $command]);

        return $this;
    }
235394
protected function addDefaultLoggingOptions()
    {
        $this
            ->addOption(
                'type',
                null,
                InputOption::VALUE_OPTIONAL,
                $this->trans('commands.database.log.common.options.type')
            )
            ->addOption(
                'severity',
                null,
                InputOption::VALUE_OPTIONAL,
                $this->trans('commands.database.log.common.options.severity')
            )
            ->addOption(
                'user-id',
                null,
                InputOption::VALUE_OPTIONAL,
                $this->trans('commands.database.log.common.options.user-id')
            );
    }
150139
public function add(Command $command, string $alias = '', bool $default = false): self
    {
        $name = $command->name();

        if ($this->commands[$name] ?? $this->aliases[$name] ?? $this->commands[$alias] ?? $this->aliases[$alias] ?? null) {
            throw new InvalidArgumentException(\sprintf('Command "%s" already added', $name));
        }

        if ($alias) {
            $command->alias($alias);
            $this->aliases[$alias] = $name;
        }

        if ($default) {
            $this->default = $name;
        }

        $this->commands[$name] = $command->version($this->version)->onExit($this->onExit)->bind($this);

        return $this;
    }
1344283
public function processArgs( ICommand &$command, $args )
    {
        $i = 0;

        $ops = array_slice( $args, 2 );

        while ( $i < count( $ops ) )
        {
            $o = $ops[ $i ];

            if ( Option::isShortCode( $o ) || Option::isLongCode( $o ) )
            {
                $option = Command::getOption( $command, $o );

                if ( $option->isRequired )
                {
                    $i++;

                    if ( !Util::validIndex( $i, $ops ) )
                    {
                        throw new CommandException( 'Missing argument for option: ' . $o );
                    }

                    Option::setRequiredValue( $option, $ops[ $i ] );
                }

                if ( $option->isOptional )
                {
                    $value = NULL;

                    if ( $option->type === Type::BOOLEAN )
                    {
                        $value = TRUE;
                    }
                    else
                    {
                        $i++;

                        $value = $ops[ $i ];
                    }

                    if ( Util::validIndex( $i, $ops ) )
                    {
                        Option::setOptionalValue( $option, $value );
                    }
                    else if ( is_bool( $value ) )
                    {
                        Option::setOptionalValue( $option, $value );
                    }
                }
            }

            $i++;
        }
    }
91747
public function fire(Command $command)
    {
        if ($command->option('verbose')) {
            $command->blockMessage('Migrations', 'Starting the module migrations ...', 'comment');
        }

        foreach ($this->modules as $module) {
            if ($command->option('verbose')) {
                $command->call('module:migrate', ['module' => $module]);
                continue;
            }
            $command->callSilent('module:migrate', ['module' => $module]);
        }
    }