Get environment engine command.

@param CommandHookInterface $command_hook

@return CommandBuilder
435556
protected function getEngineCommand(CommandHookInterface $command_hook)
    {
        $method = $command_hook->getCommand();
        $engine = $this->getEngineInstance();

        if (!method_exists($engine, $method)) {
            throw new CommandHookRuntimeException(
                sprintf("The %s method doesn't exist on the environment engine.", $method)
            );
        }
        $args = array_merge(
            $command_hook->getOptions(),
            $command_hook->getArguments()
        );

        return call_user_func_array([$engine, $method], [$args]);
    }
79228
private function parseRpbCommitHook(RpbCommitHook $hook)
    {
        if ($hook->hasName()) {
            return ['name' => $hook->name];
        }

        return $this->parseRpbModFun($hook->modfun);
    }
508552
def commandfactory(cmdline, mode='global'):
    
    # split commandname and parameters
    if not cmdline:
        return None
    logging.debug('mode:%s got commandline "%s"', mode, cmdline)
    # allow to shellescape without a space after '!'
    if cmdline.startswith('!'):
        cmdline = 'shellescape \'%s\'' % cmdline[1:]
    cmdline = re.sub(r'"(.*)"', r'"\\"\1\\""', cmdline)
    try:
        args = split_commandstring(cmdline)
    except ValueError as e:
        raise CommandParseError(str(e))
    args = [string_decode(x, 'utf-8') for x in args]
    logging.debug('ARGS: %s', args)
    cmdname = args[0]
    args = args[1:]

    # unfold aliases
    # TODO: read from settingsmanager

    # get class, argparser and forced parameter
    (cmdclass, parser, forcedparms) = lookup_command(cmdname, mode)
    if cmdclass is None:
        msg = 'unknown command: %s' % cmdname
        logging.debug(msg)
        raise CommandParseError(msg)

    parms = vars(parser.parse_args(args))
    parms.update(forcedparms)

    logging.debug('cmd parms %s', parms)

    # create Command
    cmd = cmdclass(**parms)

    # set pre and post command hooks
    get_hook = settings.get_hook
    cmd.prehook = get_hook('pre_%s_%s' % (mode, cmdname)) or \
        get_hook('pre_global_%s' % cmdname)
    cmd.posthook = get_hook('post_%s_%s' % (mode, cmdname)) or \
        get_hook('post_global_%s' % cmdname)

    return cmd
637040
public function issueEnvironmentWarnings($command_name) {
    if (!$this->warningsIssued) {
      $this->warnIfPhpOutdated();
      $this->warnIfXdebugLoaded();

      $exclude_commands = [
        'list',
        'recipes:drupalvm:init',
        'recipes:drupalvm:destroy',
      ];
      if (!in_array($command_name, $exclude_commands)) {
        $this->warnIfDrupalVmNotRunning();
      }

      $this->warningsIssued = TRUE;
    }
  }
810861
public static function getFromSapi(string $sapi): Enviroment
    {
        if (in_array($sapi, ['cli', 'phpdbg'])) {
            return Enviroment::CONSOLE();
        }

        return Enviroment::HTML();
    }
774042
public function getEnv($key = null, $default = null) {
        if (null === $key) {
            return $this->ENV;
        }

        return (isset($this->ENV[$key])) ? $this->ENV[$key] : $default;
    }
920800
public static function getHookCommand(string $hook) : string
    {
        if (!self::isValid($hook)) {
            throw new RuntimeException(sprintf('Hook \'%s\' is not supported', $hook));
        }
        return Hooks::getValidHooks()[$hook];
    }
163727
private function getSubmitAction(EnvironmentInterface $environment, $regardSelectMode = false)
    {
        if (!$regardSelectMode
            && $environment->getInputProvider()->hasParameter('select')
            && !$environment->getInputProvider()->hasValue('properties')
        ) {
            return 'select' . \ucfirst($environment->getInputProvider()->getParameter('select'));
        }

        if (null !== ($action = $this->determineAction($environment))) {
            return $action;
        }

        if ($regardSelectMode) {
            return $environment->getInputProvider()->getParameter('mode') ?: null;
        }

        return $environment->getInputProvider()->getParameter('select') ?
            'select' . \ucfirst($environment->getInputProvider()->getParameter('select')) : null;
    }
634347
private function getCommandProcessBuilder()
    {
        $pb = new ProcessBuilder();

        // PHP wraps the process in "sh -c" by default, but we need to control
        // the process directly.
        if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
            $pb->add('exec');
        }

        $pb
            ->add('php')
            ->add($this->getContainer()->getParameter('kernel.root_dir').'/console')
            ->add('--env='.$this->env)
        ;

        return $pb;
    }
680826
public function envHalt()
    {
        $this->executeCommandHook(__FUNCTION__, 'before');
        $this->engineInstance()->suspend();
        $this->executeCommandHook(__FUNCTION__, 'after');
    }
1189160
public function getEnv($key = null, $default = null)
    {
        if (null === $key)
        {
            return $_ENV;
        }

        return (isset($_ENV[$key])) ? $_ENV[$key] : $default;
    }
806958
private function lazyLoad($command_name)
    {
        if (isset($this->command_handler_ids[$command_name])) {
            list($service, $method) = $this->command_handler_ids[$command_name];

            return $this->resolve($this->container->get($service), $method);
        }

        return null;
    }
390420
def get_editor_cmd_from_environment():
    
    result = os.getenv(ENV_VISUAL)
    if (not result):
        result = os.getenv(ENV_EDITOR)
    return result
1017056
def get_hook(hook_name):
    
    if not pkg_resources.resource_exists(__name__, hook_name):
        raise HookNotFoundError
    return pkg_resources.resource_string(__name__, hook_name)
882171
protected function getCommandsByMethodEventType($method, $event_type)
    {
        $hooks = ProjectX::getProjectConfig()->getCommandHooks();
        if (empty($hooks)) {
            return [];
        }
        $info = $this->getCommandInfo($method);
        list($command, $action) = explode(':', $info->getName());

        if (!isset($hooks[$command][$action][$event_type])) {
            return [];
        }

        return $hooks[$command][$action][$event_type];
    }
67191
public function getProcess()
    {
        if (0 === count($this->prefix) && 0 === count($this->arguments)) {
            throw new LogicException('You must add() command arguments before calling getProcess().');
        }

        $arguments = array_merge($this->prefix, $this->arguments);
        $process = new Process($arguments, $this->cwd, $this->env, $this->input, $this->timeout, $this->options);

        if ($this->inheritEnv) {
            $process->inheritEnvironmentVariables();
        }
        if ($this->outputDisabled) {
            $process->disableOutput();
        }

        return $process;
    }
253393
public function envInstall()
    {
        $this->executeCommandHook(__FUNCTION__, 'before');
        $this->engineInstance()->install();
        $this->executeCommandHook(__FUNCTION__, 'after');

        return $this;
    }