Executes a cli command

@param  CliCommandOptions $options object of `cwd`, `env`, and `redirect`
@return CliCommandResponse object with output and comand information
548722
public function run(CliCommandOptions $options = null)
    {
        $options   = $this->getOptions($options);
        $command   = $this->buildCommand($options);
        $startTime = microtime(true);

        $response = $this->executor->execute(
            $command,
            $options->getCwd(),
            $options->getEnv()
        );

        $elapsedTime = microtime(true) - $startTime;
        $output      = $response->getOutput();
        $returnCode  = $response->getReturnCode();

        return new CliCommandResponse([
            'command'      => $command,
            'elapsed_time' => $elapsedTime,
            'output'       => $output,
            'start_time'   => $startTime,
            'return_code'  => $returnCode,
            'successful'   => $returnCode === 0,
        ]);
    }
1050661
public static function cli($args)
    {
        $cwd = getcwd();
        $cli = new self($cwd);

        return $cli->run(array_slice($args, 1));
    }
75631
public function execute(array $args = [], array $options = [])
    {
        $path = getcwd().'/README.md';

        $this->writeln($this->replaceVars("Project <info>{{project_name}}</info> <comment>({{project_group}})</comment>", $this->getConfig()));
        $this->writeln();

        if (is_file($path)) {
            readfile($path);
        }
    }
568583
public function envDown($opts = [
        'include-network' => false,
    ])
    {
        $this->executeCommandHook(__FUNCTION__, 'before');
        $this->engineInstance()->down($opts['include-network']);

        // Allow projects to react to the engine shutdown.
        $this->invokeEngineEvent('onEngineDown');

        // Remove hostname from the system hosts file.
        $this->removeHostName();
        $this->executeCommandHook(__FUNCTION__, 'after');

        return $this;
    }
1292174
protected function executeCurl(array $options)
    {
        curl_setopt_array($this->curl, $options);
        $result = curl_exec($this->curl);
        self::curlValidate($this->curl);

        return $result;
    }
646558
protected function executeCommand()
    {
        static $methods = [
            'HEAD',
            'GET',
            'POST',
            'PUT',
            'DELETE'
        ];

        \Akamai\Open\EdgeGrid\Client::setDebug(true);
        \Akamai\Open\EdgeGrid\Client::setVerbose(true);

        $args = $this->climate->arguments->all();
        $client = new Client();

        if ($this->climate->arguments->defined('auth-type')) {
            $auth = $this->climate->arguments->get('auth');
            if ($this->climate->arguments->get('auth-type') === 'edgegrid' ||
                (!$this->climate->arguments->defined('auth-type'))) {
                $section = 'default';
                if ($this->climate->arguments->defined('auth')) {
                    $section = (substr($auth, -1) === ':') ? substr($auth, 0, -1) : $auth;
                }
                $client = Client::createFromEdgeRcFile($section);
            }

            if (in_array($this->climate->arguments->get('auth-type'), ['basic', 'digest'])) {
                if (!$this->climate->arguments->defined('auth') || $this->climate->arguments->get('auth') === null) {
                    $this->help();
                    return;
                }

                $auth = [
                    $auth,
                    null,
                    $this->climate->arguments->get('auth-type')
                ];

                if (strpos(':', $auth[0]) !== false) {
                    list($auth[0], $auth[1]) = explode(':', $auth[0]);
                }

                $client = new Client(['auth' => $auth]);
            }
        }

        $method = 'GET';
        $options = [];
        $body = [];

        foreach ($args as $arg) {
            $value = $arg->value();
            if (empty($value) || is_bool($value) || $arg->longPrefix()) {
                continue;
            }

            if (in_array(strtoupper($value), $methods)) {
                $method = $arg->value();
                continue;
            }

            if (!isset($url) && preg_match('@^(http(s?)://|:).*$@', trim($value))) {
                $url = $value;

                if ($url{0} === ':') {
                    $url = substr($url, 1);
                }

                continue;
            }

            $matches = [];
            if (preg_match('/^(?<key>.*?):=(?<file>@?)(?<value>.*?)$/', $value, $matches)) {
                if (!$value = $this->getArgValue($matches)) {
                    return false;
                }

                $body[$matches['key']] = json_decode($value);
                continue;
            }

            if (preg_match('/^(?<header>.*?):(?<value>.*?)$/', $value, $matches)
                && !preg_match('@^http(s?)://@', $value)) {
                $options['headers'][$matches['header']] = $matches['value'];
                continue;
            }

            if (preg_match('/^(?<key>.*?)=(?<file>@?)(?<value>.*?)$/', $value, $matches)) {
                if (!$value = $this->getArgValue($matches)) {
                    return false;
                }

                $body[$matches['key']] = $matches['value'];
                continue;
            }

            if (!isset($url)) {
                $url = $value;
                continue;
            }

            $this->help();
            $this->climate->error('Unknown argument: ' . $value);

            return false;
        }

        $stdin = '';
        $fp = fopen('php://stdin', 'rb');
        if ($fp) {
            stream_set_blocking($fp, false);
            $stdin = fgets($fp);
            if (!empty(trim($stdin))) {
                while (!feof($fp)) {
                    $stdin .= fgets($fp);
                }
                fclose($fp);
            }
            $stdin = rtrim($stdin);
        }

        if (!empty($stdin) && !empty($body)) {
            $this->help();
            $this->climate->error(
                'error: Request body (from stdin or a file) and request data (key=value) cannot be mixed.'
            );
            return;
        }

        if (!empty($stdin)) {
            $body = $stdin;
        }

        if (count($body) && !$this->climate->arguments->defined('form')) {
            if (!isset($options['headers']['Content-Type'])) {
                $options['headers']['Content-Type'] = 'application/json';
            }
            if (!isset($options['headers']['Accept'])) {
                $options['headers']['Accept'] = 'application/json';
            }
            $options['body'] = (!is_string($body)) ? json_encode($body) : $body;
        }

        if (count($body) && $this->climate->arguments->defined('form')) {
            if (!isset($options['headers']['Content-Type'])) {
                $options['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
            }

            $options['body'] = (!is_string($body)) ? http_build_query($body, null, null, PHP_QUERY_RFC1738) : $body;
        }

        $options['allow_redirects'] = false;
        if ($this->climate->arguments->defined('follow')) {
            $options['allow_redirects'] = true;
        }

        return $client->request($method, $url, $options);
    }
1099970
public function execute($options = [])
    {
        if (! is_array($options) && ! $options instanceof Option) throw new \InvalidArgumentException('invalid option');

        $option = $this->getOption();
        if (is_array($options)) {
            $option->importFromArray($options);
        } else {
            $option->import($options);
        }
        $option->validate();

        $this->method->invoke($this->list, $option);
    }
274343
protected function exec($options)
    {
        $curl = curl_init();
        curl_setopt_array($curl, $options);
        $result = curl_exec($curl);
        curl_close($curl);

        return $result;
    }
437474
public function execute(array $args = [], array $options = [])
    {
        /** @var CommandInterface[] $commands */
        $commands = $this->getConfig()->get('commands');

        $all = isset($options['all']) && true === $options['all'];

        $selectedCommands = [];
        foreach ($commands as $n => $c) {
            $hidden = false;
            $realName = $n;
            if ('_' === $n{0}) {
                if (!$all) {
                    continue;
                }
                $hidden = true;
                $n = substr($n, 1);
            }
            $selectedCommands[$n] = ['hidden' => $hidden, 'realName' => $realName, 'command' => $c];
        }

        ksort($selectedCommands);

        $user = $this->getConfig()->get('user_name');

        if ($user) {
            $this->writeln('<comment>DEV Console command</comment> (Happy hacking %s !)', $user);
        } else {
            $this->writeln('<comment>DEV Console command</comment>');
        }
        $this->writeln();
        $this->writeln('%d commands:', count($selectedCommands));

        $max = 0;

        foreach ($selectedCommands as $commandName => $def) {
            $len = strlen($commandName);
            $max = $max < $len ? $len : $max;
        }

        $lastLetter = null;

        foreach ($selectedCommands as $commandName => $def) {
            $letter = $commandName{0};
            if ($lastLetter !== $letter) {
                $this->writeln();
            }
            /** @var CommandInterface $command */
            $command = $def['command'];
            $command->setConfig($this->getConfig());
            $this->writeln("  <".($def['hidden'] ? 'comment' : 'info').">%-".$max."s</".($def['hidden'] ? 'comment' : 'info').">  <comment>%s</comment>", $commandName, $command->getDescription());
            $lastLetter = $letter;
        }

        $this->writeln();
    }
287317
public function option($opt)
	{
		$args = \func_get_args();
		if ( \is_array($opt) && isset($opt[0], $this->_defaults[$opt[0]]) ){
			$this->_current_cfg[$opt[0]] = $opt[1];
		}
		else if ( isset($args[0], $args[1], $this->_defaults[$args[0]]) ){
			$this->_current_cfg[$args[0]] = $args[1];
		}
		else{
			throw new InvalidArgumentException('This configuration argument is imaginary... Sorry! :)');
		}
    return $this;
	}
209627
public function options($options)
    {
        foreach ($this->queries as $query) {
            $query->options($options);
        }

        return $this;
    }
507850
public function envSsh($opts = ['service' => null])
    {
        $this->executeCommandHook(__FUNCTION__, 'before');
        $this->engineInstance()->ssh($opts['service']);
        $this->executeCommandHook(__FUNCTION__, 'after');

        return $this;
    }
30318
public function executeCommand(CliCommand $command)
    {
        $this->command = $command;
        $this->environment = CliEnvironment::getInstance();

        switch ($command->name) {
            case static::COMMAND_PROVIDER_ALIAS . '-list-stores':
                return $this->cmdListStores();
            case static::COMMAND_PROVIDER_ALIAS . '-list-keys':
                return $this->cmdListKeys();
            case static::COMMAND_PROVIDER_ALIAS . '-get':
                return $this->cmdGet();
            case static::COMMAND_PROVIDER_ALIAS . '-delete':
                $this->cmdDelete();
                exit;
            case static::COMMAND_PROVIDER_ALIAS . '-clear-expired':
                $this->cmdClear(true);
                exit;
            case static::COMMAND_PROVIDER_ALIAS . '-clear':
                $this->cmdClear();
                exit;
            case static::COMMAND_PROVIDER_ALIAS . '-backup':
                $this->cmdBackup();
                exit;
            case static::COMMAND_PROVIDER_ALIAS . '-restore':
                $this->cmdRestore();
                exit;
            case static::COMMAND_PROVIDER_ALIAS . '-destroy':
                $this->cmdDestroy();
                exit;
            default:
                throw new \LogicException(
                    'Command named[' . $command->name . '] is not provided by class[' . get_class($this) . '].'
                );
        }
    }
1210137
public function setOptions(OptionsInterface $options = null)
    {
        if (null !== $options && !$options instanceof Options) {
            $options = new Options($options->toArray());
        }

        $this->options = $options;
        return $this;
    }
1113628
public function execute($command = null, array $args = array(), array $options = array())
    {
        $command = $command ?: $this->defaultCommand;
        if (!isset($this->commands[$command])) {
            throw new ConsoleException("Command '$command' does not exist");
        }
        
        $callback = $this->commands[$command];
        if (is_callable($callback)) {
            $params = array($args, $options);
            if (is_string($callback)) {
                if (strpos($callback, '::') !== false) {
                    list($classname, $methodname) = explode('::', $callback);
                    $reflection = new ReflectionMethod($classname, $methodname);
                } else {
                    $reflection = new ReflectionFunction($callback);
                }
                $params = Utils::computeFuncParams($reflection, $args, $options);
            }
            $params[] = $this;
            return call_user_func_array($callback, $params);
        }

        $method = new ReflectionMethod($callback, 'execute');
        $params = Utils::computeFuncParams($method, $args, $options);
        return $method->invokeArgs(new $callback($this), $params);
    }
828709
public function runCommand($command, array $options = [])
    {
        if (!is_array($command) && !is_object($command)) {
            throw new InvalidArgumentException(
                sprintf(
                    '$command must be an array or an object, %s given.',
                    \Tequila\MongoDB\getType($command)
                )
            );
        }

        $readPreference = isset($options['readPreference'])
            ? $options['readPreference']
            : $this->readPreference;

        if (!$readPreference instanceof ReadPreference) {
            throw new InvalidArgumentException(
                sprintf(
                    'Option "readPreference" is expected to be an instance of %s, %s given.',
                    ReadPreference::class,
                    \Tequila\MongoDB\getType($readPreference)
                )
            );
        }

        if (!$command instanceof \MongoDB\Driver\Command) {
            $command = new \MongoDB\Driver\Command($command);
        }
        $server = $this->manager->selectServer($readPreference);
        $cursor = $server->executeCommand($this->databaseName, $command);

        return new CommandCursor($cursor);
    }
997680
public function execute(array $args = [], array $options = [])
    {
        $argv = $_SERVER['argv'];
        array_shift($argv);
        array_shift($argv);

        $argvString = '';
        foreach ($argv as $arg) {
            $argvString .= ($argvString ? ' ' : '').'"'.str_replace('"', '\\"', $arg).'"';
        }
        $found = null;
        foreach ($this->getConfig()->get('_shell_scripts_dirs', []) as $dir) {
            $path = sprintf('%s/%s', $dir, $this->script);
            if (!is_file($path)) {
                continue;
            }
            $found = $path;
        }
        if (null === $found) {
            throw new \RuntimeException(sprintf("Unknown shell script '%s'", $this->script), 412);
        }

        $this->executeShellCommand(sprintf('%s %s', $found, $argvString), $options);
    }