public function connectCommand(Command $cmd)
    {
        $name = $cmd->name();
        $this->commands[$name] = $cmd;

        // regsiter command aliases to the alias table.
        $aliases = $cmd->aliases();
        if (is_string($aliases)) {
            $aliases = preg_split('/\s+/', $aliases);
        }

        if (!is_array($aliases)) {
            throw new InvalidArgumentException('Aliases needs to be an array or a space-separated string.');
        }

        foreach ($aliases as $alias) {
            $this->aliases[$alias] = $cmd;
        }
    }