build show sub command

NOTE: for technical reasons $name is optional, however under normal
implementation it SHOULD be passed!

@param string $name
@param bool   $queryRemotes Fetch new information from remotes

@return ShowSubCommand
439148
public function prepare($name = null, $queryRemotes = true)
    {
        $this->addCommandName(self::GIT_REMOTE_SHOW);
        /**
         *  only add subject if relevant,
         *  otherwise on repositories without a remote defined (ie, fresh
         *  init'd or mock) will likely trigger warning/error condition
         *
         */
        if ($name) {
            $this->addCommandSubject($name);
        }

        if (!$queryRemotes) {
            $this->addCommandArgument('-n');
        }

        return $this;
    }
258443
public function debug(?string $name = null)
    {
        return $name !== null ? $this->query[$name] : $this->query;
    }
863901
public function addSubQuery(
        string $name,
        Query $query
    ): self {
        $this->subqueries[$name] = $query;

        return $this;
    }
164474
protected function getViewStub($method = null, $name = null)
    {
        if (in_array($name, [ $this->qualifyClass('ModelController'), $this->qualifyClass('Model/ChildController') ])) {
            if ($this->option('parent')) {
                return __DIR__.'/stubs/view.nested.model.'.$method.'.stub';
            } elseif ($this->option('model') || $this->option('resource')) {
                return __DIR__.'/stubs/view.model.'.$method.'.stub';
            }
        }

        if ($this->option('parent')) {
            return __DIR__.'/stubs/view.nested.'.$method.'.stub';
        } elseif ($this->option('model') || $this->option('resource')) {
            return __DIR__.'/stubs/view.'.$method.'.stub';
        }

        return __DIR__.'/stubs/view.stub';
    }
800277
public function sub($name, $attrs = null, $ns = null)
    {
        //@TODO: attrs is ignored
        foreach ($this->subs as $sub) {
            if ($sub->name === $name and ($ns === null or $sub->ns === $ns)) {
                return $sub;
            }
        }
        return null;
    }
277679
public function hasSubsidiary($name)
    {
        $class = $this->getSubsidiaryClass($name);
        if (empty($class)) {
            return false;
        }
        $query = $class::find();
        if (!method_exists($query, 'createdBy')) {
            return false;
        }
        return $query->createdBy($this)->exists();
    }
1084404
public function get($name)
    {
        if (!isset($this->commands[$name])) {
            throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
        }

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

        if ($this->wantHelps) {
            $this->wantHelps = false;

            $helpCommand = $this->get('help');
            $helpCommand->setCommand($command);

            return $helpCommand;
        }

        return $command;
    }
634290
function getCommands($name, $unique = false)
    {
        if (!isset($this->commands[$name])){
            $this->commands[$name] = [];
        }
        if ($unique){
            $keys = [];
            $result = [];
            foreach ($this->commands[$name] as $com){
                $key = serialize($com);
                if (!isset($keys[$key])){
                    $result[] = $com;
                    $keys[$key] = true;
                }
            }
            unset($keys);
            return $result;
        }
        return $this->commands[$name];
    }
699079
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        if (isset($this->instances[$requestedName])) {
            return $this->instances[$requestedName];
        }

        /* @var $serviceLocator \Zend\ServiceManager\ServiceManager */
        $config  = $this->getConfig($serviceLocator);
        $params = $config[$requestedName];

        $port = isset($params['port']) ? ':' . $params['port'] : '';

        $connector = new ZendConnector(new XmlRpcClient('http://' . $params['host'] . $port . '/RPC2'));

        $connector->setCredentials($params['username'], $params['password']);

        $this->instances[$requestedName] = $supervisor = new Supervisor($connector);

        return $supervisor;
    }
452183
public static function build($name, array $configs = array())
    {
        if (isset(self::$instantiated[$name])) {
            return self::$instantiated[$name];
        }

        self::instantiateDefaultBroadcasters();
        if (!isset(self::$broadcasters[$name])) {
            throw new InvalidArgumentException(sprintf('Undefined broadcaster with name "%s".', $name));
        }

        self::$instantiated[$name] = self::instantiate(self::$broadcasters[$name], $configs);

        return self::$instantiated[$name];
    }
280964
public static function fromCommandClass($name, $subCommand = null)
    {
        $prefix = 'execute';
        $class = new ReflectionClass($name);

        if ($subCommand) {
            $method = $prefix . ucfirst(Utils::camelize($subCommand));
            if (!$class->hasMethod($method)) {
                throw new ConsoleException("Sub command '$subCommand' of '$name' does not exist");
            }
            return new Help($class->getMethod($method)->getDocComment());
        }

        $help = new Help($class->getDocComment());
        foreach ($class->getMethods() as $method) {
            if (strlen($method->getName()) > strlen($prefix) && 
                substr($method->getName(), 0, strlen($prefix)) === $prefix) {
                    $help->subCommands[] = Utils::dashized(substr($method->getName(), strlen($prefix)));
            }
        }
        return $help;
    }
799493
public function getCommand(string $name): AbstractCommand
	{
		$this->initCommands();

		if (!$this->hasCommand($name))
		{
			throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
		}

		// If the command isn't registered, pull it from the loader
		if (!isset($this->commands[$name]))
		{
			$this->addCommand($this->commandLoader->get($name));
		}

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

		// If the user requested help, we'll fetch the help command now and inject the user's command into it
		if ($this->wantsHelp)
		{
			$this->wantsHelp = false;

			/** @var HelpCommand $helpCommand */
			$helpCommand = $this->getCommand('help');
			$helpCommand->setCommand($command);

			return $helpCommand;
		}

		return $command;
	}
1145309
public function setName($name)
    {
        if (null !== $name) {
            Assert::string($name, 'The command name must be a string or null. Got: %s');
            Assert::notEmpty($name, 'The command name must not be empty.');
            Assert::greaterThan(strlen($name), 1, sprintf('The command name should contain at least two characters. Got: "%s"', $name));
        }

        parent::setName($name);

        return $this;
    }
860267
public function getCommandNamed($name)
    {
        foreach ($this->commands as $command) {
            if ($name === $command->getName()) {
                return $command;
            }
        }

        throw new DcGeneralInvalidArgumentException('Command with name ' . $name . ' not found');
    }
501581
public function createView ($name, Query $query, $replace = true)
		{
			echo "    > create table $name ...";
			$time = microtime(true);

			$sql = 'CREATE' . ( $replace ? ' OR REPLACE' : '' ) . ' VIEW ' . $this->db->quoteTableName($name) . ' AS ' . $query->createCommand()->getRawSql();
			$this->db->createCommand($sql)->execute();

			echo '    > done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n";
		}
502174
protected function buildView($name, $method = null)
    {
        $replace = [];

        if ($this->option('parent')) {
            $replace = $this->buildParentReplacements();
        }

        if ($this->option('model')) {
            $replace = $this->buildModelReplacements($replace);
        }

        if ($this->option('parent')) {
            $replace['parent_dummy_view'] = $this->getParentViewName($name);
            $replace['parent_dummy_route'] = $this->getParentRouteName($name);
        }
        $replace['dummy_view'] = $this->getViewName($name);
        $replace['dummy_route'] = $this->getRouteName($name);

        return str_replace(array_keys($replace), array_values($replace), $this->files->get($this->getViewStub($method, $name)));
    }
625264
public function spartanRemote(string $name): array
    {
        $remotes = $this->spartanRemotes();

        list($user, $host, $path, $port) = preg_split('/[@\:]/', $name) + [null, null, null, 22];

        if (isset($remotes[$user])) {
            $globalRemote = $remotes[$user];
            $path         = $host;

            $user = $globalRemote['user'];
            $host = $globalRemote['host'];
            $port = (int)$globalRemote['port'];
        }

        return [
            'user' => $user,
            'host' => $host,
            'path' => $path ?: '~',
            'port' => $port,
            'auth' => "{$user}@{$host}",
        ];
    }