Add a command to the collection

@param string $name The name of the command you want to map.
@param string|\Cake\Console\Shell|\Cake\Console\Command $command The command to map.
@return $this
547994
public function add($name, $command)
    {
        // Once we have a new Command class this should check
        // against that interface.
        if (!is_subclass_of($command, Shell::class) && !is_subclass_of($command, Command::class)) {
            $class = is_string($command) ? $command : get_class($command);
            throw new InvalidArgumentException(
                "Cannot use '$class' for command '$name' it is not a subclass of Cake\Console\Shell or Cake\Console\Command."
            );
        }
        if (!preg_match('/^[^\s]+(?:(?: [^\s]+){1,2})?$/ui', $name)) {
            throw new InvalidArgumentException(
                "The command name `{$name}` is invalid. Names can only be a maximum of three words."
            );
        }

        $this->commands[$name] = $command;

        return $this;
    }
152955
protected function addConsoleCommand(Command $command)
    {
        Deprecated::method(3.0, 'registerNutCommands');

        $app = $this->getContainer();
        $app['nut.commands.add']($command);
    }
1200018
public function addCommands(array $commands)
    {
        foreach ($commands as $name => $command) {
            $this->addCommand($command, is_numeric($name) ? null : $name);
        }
        return $this;
    }
41300
public function add(BaseCommand $command)
    {
        if ($ret = parent::add($command)) {
            if ($ret instanceof ContextAware) {
                $ret->setContext($this->context);
            }

            if ($ret instanceof PresenterAware) {
                $ret->setPresenter($this->config->getPresenter());
            }

            if (isset($this->commandsMatcher)) {
                $this->commandsMatcher->setCommands($this->all());
            }
        }

        return $ret;
    }
776384
public function setCommand($command, $base = null)
    {

        $base = ($base === null) ? BASE : $base;

        parent::setCommand($this->resolveBase($base).'anonym '.$command);
        return $this;
    }
349768
public function add_command($command)
    {
        if (is_string($command)) {
            $command = (new \ReflectionClass($command))->newInstance(self::$CI);
        }

        if (!$command instanceof Commands) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Argument 1 passed to %s must be an instance of %s, %s given',
                    __NAMESPACE__ . '\Cli::add_command()',
                    __NAMESPACE__ . '\Commands',
                    gettype($command)
                )
            );
        }

        $this->commands[$command->name()] = $command;
    }
1293239
public function setCommand($command)
    {
        if (!preg_match(self::$_regex['command'], $command)) {
            throw new \InvalidArgumentException(sprintf('Command "%s" is incorect', $command));
        }

        $this->command = $command;

        return $this->generateHash();
    }
10311
public function bind($command)
    {
        $this->command = $command;
        $this->config = $command->getApplication()->config();
        $this->init();

        return $this;
    }
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;
    }
93324
public function add(ICommand $command, bool $overwrite = false)
    {
        if (!$overwrite && $this->has($command->getName())) {
            throw new InvalidArgumentException("A command with name \"{$command->getName()}\" already exists");
        }

        $command->setCommandCollection($this);
        $this->commands[$command->getName()] = $command;
    }
936920
public function add(Command $command)
    {
        $command->setApplication($this);

        if (!$command->isEnabled()) {
            $command->setApplication(null);

            return;
        }

        if (null === $command->getDefinition()) {
            throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command)));
        }

        $this->commands[$command->getName()] = $command;

        foreach ($command->getAliases() as $alias) {
            $this->commands[$alias] = $command;
        }

        return $command;
    }
539168
public function addCommand(CommandInterface $command): SectionInterface
    {
        if (isset($this->commands[$command->getName()])) {
            throw new CommandExistsException(sprintf('Command with name "%s" already exists.', $command->getName()));
        }
        $this->commands[$command->getName()] = $command;

        return $this;
    }
411609
public function addCommand(string $name, $handler = null, $option = null): self
    {
        return $this->command($name, $handler, $option);
    }
254013
public function add($command)
    {
        if (is_string($command)) {
            $command = new $command($this->container);
        }

        if (!$command instanceof Console\Commands) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Argument 1 passed to %s must be an instance of %s, %s given',
                    __FUNCTION__,
                    Console\Commands::class,
                    get_class($command)
                )
            );
        }

        if (array_key_exists($command->name(), $this->commands)) {
            throw new \RuntimeException(
                sprintf('Command %s already registered', $command->name())
            );
        }

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

        return $this;
    }
460688
public function command(
        string $name,
        string $desc = '',
        string $alias = '',
        bool $allowUnknown = false,
        bool $default = false
    ): Command {
        $command = new Command($name, $desc, $allowUnknown, $this);

        $this->add($command, $alias, $default);

        return $command;
    }
1210691
public function addCommand($command, $config = array())
    {
        if (!($command instanceof ControllerToolbarCommand)) {
            $command = $this->getCommand($command, $config);
        }

        return $this->getDelegate()->addCommand($command, $config);
    }
551186
public function addCommand($command, $config = array())
    {
        if (! ($command instanceof  AnControllerToolbarCommand)) {
            $command = $this->getCommand($command, $config);
        }

        $this->_commands[$command->getName()] = $command;
        return $this;
    }