@param RawArgs $args
@param Command $currentCommand

@return ResolveResult
179874
private function processDefaultSubCommands(RawArgs $args, Command $currentCommand)
    {
        if ($result = $this->processDefaultCommands($args, $currentCommand->getDefaultSubCommands())) {
            return $result;
        }

        // No default commands, return the current command
        return new ResolveResult($currentCommand, $args);
    }
441565
public function handleUpdate(Args $args)
    {
        $flags = $args->isOptionSet('force')
            ? RepositoryManager::OVERRIDE | RepositoryManager::IGNORE_FILE_NOT_FOUND
            : RepositoryManager::OVERRIDE;
        $repositoryPath = Path::makeAbsolute($args->getArgument('path'), $this->currentPath);
        $mappingToUpdate = $this->repoManager->getRootPathMapping($repositoryPath);
        $pathReferences = array_flip($mappingToUpdate->getPathReferences());

        foreach ($args->getOption('add') as $pathReference) {
            $pathReferences[$pathReference] = true;
        }

        foreach ($args->getOption('remove') as $pathReference) {
            unset($pathReferences[$pathReference]);
        }

        if (0 === count($pathReferences)) {
            $this->repoManager->removeRootPathMapping($repositoryPath);

            return 0;
        }

        $updatedMapping = new PathMapping($repositoryPath, array_keys($pathReferences));

        if ($this->mappingsEqual($mappingToUpdate, $updatedMapping)) {
            throw new RuntimeException('Nothing to update.');
        }

        $this->repoManager->addRootPathMapping($updatedMapping, $flags);

        return 0;
    }
877827
public function resolve(BindingInterface $binding, Container $container, $args = [], $explicit = null)
    {
        return $binding->resolve($container, $args, $explicit);
    }
868660
public function handle($args = null)
    {
        $this->_args = $args !== null ? $args : $GLOBALS['argv'];

        list(, $controllerName, $commandName) = array_pad($this->_args, 3, null);
        if ($commandName !== null && $commandName[0] === '-') {
            $commandName = null;
        }

        if ($controllerName === 'list') {
            $controllerName = 'help';
            $commandName = $commandName ?: 'list';
        } elseif ($controllerName === null) {
            $controllerName = 'help';
        } elseif ($controllerName === 'help' && $commandName !== null && $commandName !== 'list') {
            $controllerName = $commandName;
            $commandName = 'help';
        }

        $controllerName = Text::camelize($controllerName);
        $commandName = lcfirst(Text::camelize($commandName));

        $controllerClassName = null;

        if ($this->alias->has('@ns.cli')) {
            $namespaces = ['@ns.cli', 'ManaPHP\\Cli\\Controllers'];
        } else {
            $namespaces = ['ManaPHP\\Cli\\Controllers'];
        }

        foreach ($namespaces as $prefix) {
            $className = $this->alias->resolveNS($prefix . '\\' . $controllerName . 'Controller');

            if (class_exists($className)) {
                $controllerClassName = $className;
                break;
            }
        }

        if (!$controllerClassName) {
            $guessed = $this->_guessController($controllerName);
            if ($guessed) {
                $controllerClassName = $guessed;
                $controllerName = basename(substr($controllerClassName, strrpos($controllerClassName, '\\')), 'Controller');
            } else {
                return $this->console->error(['`:command` command is not exists', 'command' => lcfirst($controllerName) . ':' . $commandName]);
            }
        }

        $controllerInstance = $this->_di->getShared($controllerClassName);
        if ($commandName === '') {
            $commands = $this->_getCommands($controllerClassName);
            if (count($commands) === 1) {
                $commandName = $commands[0];
            } elseif (in_array('default', $commands, true)) {
                $commandName = 'default';
            } else {
                $commandName = 'help';
            }
        }

        if ($commandName !== 'help' && in_array('--help', $this->_args, true)) {
            $commandName = 'help';
        }

        if (!method_exists($controllerInstance, $commandName . 'Command')) {
            $guessed = $this->_guessCommand($controllerClassName, $commandName);
            if (!$guessed) {
                return $this->console->error(['`:command` sub command is not exists', 'command' => lcfirst($controllerName) . ':' . $commandName]);
            } else {
                $commandName = $guessed;
            }
        }

        try {
            $r = $this->commandInvoker->invoke($controllerInstance, $commandName);
        } /** @noinspection PhpRedundantCatchClauseInspection */
        catch (ArgumentsException $e) {
            return $this->console->error($e->getMessage());
        }

        return is_int($r) ? $r : 0;
    }
245491
public function passthru($args = [])
    {
        $command = $this->prepareCommand($args);
        Yii::info("> $command");
        passthru($command, $exitcode);

        return $exitcode;
    }
685546
public function run(RawArgs $args, IO $io)
    {
        return $this->handle($this->parseArgs($args), $io);
    }
478
public function find_subcommand( &$args ) {
		$name = array_shift( $args );

		$subcommands = $this->get_subcommands();

		if ( ! isset( $subcommands[ $name ] ) ) {
			$aliases = self::get_aliases( $subcommands );

			if ( isset( $aliases[ $name ] ) ) {
				$name = $aliases[ $name ];
			}
		}

		if ( ! isset( $subcommands[ $name ] ) ) {
			return false;
		}

		return $subcommands[ $name ];
	}
774477
public function executeCommand($command, $arguments = array())
    {
        $command = $this->client->getCommand($command, $arguments);
        return $this->client->execute($command);/*$command->getResponse()->json();*/
    }
994406
public function execute(array $args, array $options = array())
    {
        if (!count($args)) {
            throw new ConsoleException("Missing subcommand name");
        }
        
        $command = ucfirst(Utils::camelize(array_shift($args)));
        $methodName = "execute$command";
        if (!method_exists($this, $methodName)) {
            throw new ConsoleException("Command '$command' does not exist");
        }

        $method = new ReflectionMethod($this, $methodName);
        $params = Utils::computeFuncParams($method, $args, $options);
        return $method->invokeArgs($this, $params);
    }
1348472
public function resolve(string $name, ...$args)
    {
        //if we can't resolve it
        if (!$this->canResolve($name)) {
            throw ResolverException::forResolverNotFound($name);
        }

        //is it registered ?
        if ($this->isRegistered($name)) {
            $callback = $this->registry[$name];
            return call_user_func_array($callback, $args);
        }

        //if class exist
        if (class_exists($name)) {
            //it is a class, let's register this
            $this->register($name, function (...$args) use ($name) {
                //if the static method i exists
                if (method_exists($name, 'i')) {
                    //instantiate it
                    return forward_static_call_array([$name, 'i'], $args);
                }

                return new $name(...$args);
            });

            //then resolve this
            return $this->resolve($name, ...$args);
        }

        //its callable, let's register this
        $this->register($name, function (...$args) use ($name) {
            return call_user_func_array($name, $args);
        });

        //then resolve this
        return $this->resolve($name, ...$args);
    }
45076
public function handleAdd(Args $args)
    {
        $flags = $args->isOptionSet('force')
            ? DiscoveryManager::OVERRIDE | DiscoveryManager::IGNORE_TYPE_NOT_FOUND
                | DiscoveryManager::IGNORE_TYPE_NOT_ENABLED
            : 0;

        $bindingParams = array();
        $artifact = $args->getArgument('artifact');

        $this->parseParams($args, $bindingParams);

        if (false !== strpos($artifact, '\\') || $args->isOptionSet('class')) {
            $binding = new ClassBinding(
                $artifact,
                $args->getArgument('type'),
                $bindingParams
            );
        } else {
            $binding = new ResourceBinding(
                Path::makeAbsolute($artifact, $this->currentPath),
                $args->getArgument('type'),
                $bindingParams,
                $args->getOption('language')
            );
        }

        $this->discoveryManager->addRootBindingDescriptor(new BindingDescriptor($binding), $flags);

        return 0;
    }
47576
public static function callArgs($callback, array $args = [])
    {
        try {
            $callback = static::evaluateCallback($callback);

            return \call_user_func_array($callback, $args);
        } catch (\Exception $e) {
            $message = $e->getMessage();
        }

        if (\is_array($callback) && \is_object($callback[0])) {
            $callback[0] = \get_class($callback[0]);
        }

        throw new DcGeneralRuntimeException(
            \sprintf(
                'Execute callback %s failed - Exception message: %s',
                (\is_array($callback)
                    ? \implode('::', $callback)
                    : (\is_string($callback)
                        ? $callback
                        : \get_class(
                            $callback
                        ))),
                $message
            ),
            0,
            $e
        );
    }
187377
public function submit(array $command, array $args)
    {
        $result = (array) $this->callHandler($command, 'submit', $args);
        $result += array('redirect' => '', 'message' => '', 'severity' => '');
        return $result;
    }
1321806
public function handleEnable(Args $args)
    {
        $bindingToEnable = $this->getBindingByUuidPrefix($args->getArgument('uuid'));

        if ($bindingToEnable->getContainingModule() instanceof RootModule) {
            throw new RuntimeException(sprintf(
                'Cannot enable bindings in the module "%s".',
                $bindingToEnable->getContainingModule()->getName()
            ));
        }

        $this->discoveryManager->enableBindingDescriptor($bindingToEnable->getUuid());

        return 0;
    }
100907
private function resolveArgs(array $args)
    {
        $resolved = [];
        foreach ($args as $argDefinition) {
            switch ($argDefinition['type']) {
                case 'lookup':
                    $resolved[] = $this->lookupRecursive($argDefinition['item']);
                    break;
                case 'value':
                    $resolved[] = $argDefinition['item'];
                    break;
            }
        }

        return $resolved;
    }
322529
public function resolve(Container $container, array $args = [], $explicit = null)
    {
        $definition = $this->definition;

        if (!is_null($explicit) && !empty($explicit)) {
            $definition = $explicit;
        }

        if (is_string($definition)) {
            // a string should be resolved once only, if more than one, it mean that the class behind the
            // string have also dependency on itself and may go on infinite loop
            $this->n++;
            if ($this->n > 1) {
                throw new InfiniteLoopResolutionException($definition);
            }
            $args = $this->classResolver->resolve($definition, $container, $args, $explicit);
            $instance = $this->instantiator->instantiate($definition, $args);
            // since it is a prototype, when we reach this line, it mean that prototype has been resolved properly,
            // so we decrease $n to allow other call to this prototype
            $this->n--;
            return $instance;
        } elseif (is_array($definition)) {
            return $this->arrayDefinition
                ->newInstancesOnly()
                ->resolve($definition, $container, $args);
        }

        throw new \Exception(__CLASS__.': Invalid definition for '.$this->name);
    }
1016476
protected function parse($command, array $arguments = array(), $output)
    {
        if (null !== $this->parser) {
            return $this->parser->parse($command, $arguments, $output);
        }

        return $output;
    }