Runs interactive bash shell in RoboCI environment
@param $environment
@param string $args
548041
public function ciShell($environment, $args = '')
    {
        $runner = new Runner($environment);

        $res = $runner->buildImage();
        if (!$res->wasSuccessful()) return 1;
        $runner->runServices();

        $links = array_keys($runner->getServices());
        $links = implode(' ', array_map(function($l) {return "--link $l";}, $links ));

        $command = (new DockerRun(Config::$runImage))
            ->option('-t')
            ->option('-i')
            ->name('robo_shell_'.uniqid())
            ->arg($links)
            ->arg($args)
            ->exec('bash')
            ->getCommand();

        $this->yell("To enter shell run `$command`\n");
    }
365672
public function run(array $args = null) {
		$exec = escapeshellcmd($this->command);
		if ($args) {
			$exec .= " ". implode(" ", array_map("escapeshellarg", (array) $args));
		}
		
		if ($this->sudo) {
			$this->suExec(sprintf($this->sudo." 2>&1", $exec), $this->verbose);
		} elseif ($this->verbose) {
			ob_start(function($s) {
				$this->output .= $s;
				return $s;
			}, 1);
			passthru($exec, $this->status);
			ob_end_flush();
		} elseif ($this->verbose !== false /* !quiet */) {
			ob_start([$this, "progress"], 1);
			passthru($exec . " 2>&1", $this->status);
			ob_end_flush();
		} else {
			exec($exec ." 2>&1", $output, $this->status);
			$this->output = implode("\n", $output);
		}
		
		if ($this->status) {
			throw new Exception("Command {$exec} failed ({$this->status})");
		}

		return $this;
	}
449744
public function execute(array $args, array $options = [])
    {
        $this->bootstrap($args, $options);

        $version = isset($options['target']) ? $options['target'] : $options['t'];
        $date = isset($options['date']) ? $options['date'] : $options['d'];
        $force = isset($options['force']) ? $options['force'] : $options['f'];

        // rollback the specified environment
        $start = microtime(true);
        if (null !== $date) {
            $this->getManager()->rollbackToDateTime(new \DateTime($date), $force);
        } else {
            $this->getManager()->rollback($version, $force);
        }
        $end = microtime(true);

        Output::writeln('');
        Output::writeln(Colour::colour('All Done. Took ', Colour::GREEN) . sprintf('%.4fs', $end - $start));
    }
841911
public function execute($args)
    {
        self::$definedProps = new Properties();
        $this->searchForThis = null;

        // 1) First handle any options which should always
        // Note: The order in which these are executed is important (if multiple of these options are specified)

        if (in_array('-help', $args) || in_array('-h', $args)) {
            static::printUsage();

            return;
        }

        if (in_array('-version', $args) || in_array('-v', $args)) {
            static::printVersion();

            return;
        }

        if (in_array('-init', $args) || in_array('-i', $args)) {
            $key = array_search('-init', $args) ?: array_search('-i', $args);
            $path = isset($args[$key + 1]) ? $args[$key + 1] : null;

            self::init($path);

            return;
        }

        if (in_array('-diagnostics', $args)) {
            Diagnostics::doReport(new PrintStream(self::$out));

            return;
        }

        // 2) Next pull out stand-alone args.
        // Note: The order in which these are executed is important (if multiple of these options are specified)

        if (false !== ($key = array_search('-quiet', $args, true)) || false !== ($key = array_search(
            '-q',
            $args,
            true
        ))
        ) {
            self::$msgOutputLevel = Project::MSG_WARN;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-emacs', $args, true))
            || false !== ($key = array_search('-e', $args, true))
        ) {
            $this->emacsMode = true;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-verbose', $args, true))) {
            self::$msgOutputLevel = Project::MSG_VERBOSE;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-debug', $args, true))) {
            self::$msgOutputLevel = Project::MSG_DEBUG;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-silent', $args, true))
            || false !== ($key = array_search('-S', $args, true))
        ) {
            $this->silent = true;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-propertyfileoverride', $args, true))) {
            $this->propertyFileOverride = true;
            unset($args[$key]);
        }

        // 3) Finally, cycle through to parse remaining args
        //
        $keys = array_keys($args); // Use keys and iterate to max(keys) since there may be some gaps
        $max = $keys ? max($keys) : -1;
        for ($i = 0; $i <= $max; $i++) {
            if (!array_key_exists($i, $args)) {
                // skip this argument, since it must have been removed above.
                continue;
            }

            $arg = $args[$i];

            if ($arg == "-logfile") {
                try {
                    // see: http://phing.info/trac/ticket/65
                    if (!isset($args[$i + 1])) {
                        $msg = "You must specify a log file when using the -logfile argument\n";
                        throw new ConfigurationException($msg);
                    }

                    $logFile = new PhingFile($args[++$i]);
                    $out = new FileOutputStream($logFile); // overwrite
                    self::setOutputStream($out);
                    self::setErrorStream($out);
                    self::$isLogFileUsed = true;
                } catch (IOException $ioe) {
                    $msg = "Cannot write on the specified log file. Make sure the path exists and you have write permissions.";
                    throw new ConfigurationException($msg, $ioe);
                }
            } elseif ($arg == "-buildfile" || $arg == "-file" || $arg == "-f") {
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a buildfile when using the -buildfile argument.";
                    throw new ConfigurationException($msg);
                }

                $this->buildFile = new PhingFile($args[++$i]);
            } elseif ($arg == "-listener") {
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a listener class when using the -listener argument";
                    throw new ConfigurationException($msg);
                }

                $this->listeners[] = $args[++$i];
            } elseif (StringHelper::startsWith("-D", $arg)) {
                // Evaluating the property information //
                // Checking whether arg. is not just a switch, and next arg. does not starts with switch identifier
                if (('-D' == $arg) && (!StringHelper::startsWith('-', $args[$i + 1]))) {
                    $name = $args[++$i];
                } else {
                    $name = substr($arg, 2);
                }

                $value = null;
                $posEq = strpos($name, "=");
                if ($posEq !== false) {
                    $value = substr($name, $posEq + 1);
                    $name = substr($name, 0, $posEq);
                } elseif ($i < count($args) - 1 && !StringHelper::startsWith("-D", $args[$i + 1])) {
                    $value = $args[++$i];
                }
                self::$definedProps->setProperty($name, $value);
            } elseif ($arg == "-logger") {
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a classname when using the -logger argument";
                    throw new ConfigurationException($msg);
                }

                $this->loggerClassname = $args[++$i];
            } elseif ($arg == "-no-strict") {
                $this->strictMode = false;
            } elseif ($arg == "-strict") {
                $this->strictMode = true;
            } elseif ($arg == "-inputhandler") {
                if ($this->inputHandlerClassname !== null) {
                    throw new ConfigurationException("Only one input handler class may be specified.");
                }
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a classname when using the -inputhandler argument";
                    throw new ConfigurationException($msg);
                }

                $this->inputHandlerClassname = $args[++$i];
            } elseif ($arg === "-propertyfile") {
                $i = $this->handleArgPropertyFile($args, $i);
            } elseif ($arg === "-keep-going" || $arg === "-k") {
                $this->keepGoingMode = true;
            } elseif ($arg == "-longtargets") {
                self::$definedProps->setProperty('phing.showlongtargets', 1);
            } elseif ($arg == "-projecthelp" || $arg == "-targets" || $arg == "-list" || $arg == "-l" || $arg == "-p") {
                // set the flag to display the targets and quit
                $this->projectHelp = true;
            } elseif ($arg == "-find") {
                // eat up next arg if present, default to build.xml
                if ($i < count($args) - 1) {
                    $this->searchForThis = $args[++$i];
                } else {
                    $this->searchForThis = self::DEFAULT_BUILD_FILENAME;
                }
            } elseif (substr($arg, 0, 1) == "-") {
                // we don't have any more args
                self::printUsage();
                self::$err->write(PHP_EOL);
                throw new ConfigurationException("Unknown argument: " . $arg);
            } else {
                // if it's no other arg, it may be the target
                $this->targets[] = $arg;
            }
        }

        // if buildFile was not specified on the command line,
        if ($this->buildFile === null) {
            // but -find then search for it
            if ($this->searchForThis !== null) {
                $this->buildFile = $this->_findBuildFile(self::getProperty("user.dir"), $this->searchForThis);
            } else {
                $this->buildFile = new PhingFile(self::DEFAULT_BUILD_FILENAME);
            }
        }

        try {
            // make sure buildfile (or buildfile.dist) exists
            if (!$this->buildFile->exists()) {
                $distFile = new PhingFile($this->buildFile->getAbsolutePath() . ".dist");
                if (!$distFile->exists()) {
                    throw new ConfigurationException(
                        "Buildfile: " . $this->buildFile->__toString() . " does not exist!"
                    );
                }
                $this->buildFile = $distFile;
            }

            // make sure it's not a directory
            if ($this->buildFile->isDirectory()) {
                throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " is a dir!");
            }
        } catch (IOException $e) {
            // something else happened, buildfile probably not readable
            throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " is not readable!");
        }

        $this->loadPropertyFiles();

        $this->readyToRun = true;
    }
1306666
private function handleEditAllAction(EnvironmentInterface $environment, Action $action)
    {
        $this->clearClipboard($environment);
        $this->handleGlobalCommands($environment);
        $this->handleSessionOverrideEditAll(
            $this->getModelIds($environment, $action, $this->getSubmitAction($environment)),
            'properties',
            $environment
        );

        return  $this->callAction($environment, 'editAll', ['mode' => 'edit']);
    }
682285
public function run(InputInterface $input, OutputInterface $output, array $args)
    {
        $arguments = [];
        $options   = [];

        foreach ($args as $arg) {
            $matches = [];
            if (0 < preg_match('/^\-{1,2}(?<key>[^\=]+)(\=(?<value>.*))?$/', $arg, $matches)) {
                $options[$matches['key']] = isset($matches['value']) ? $matches['value'] : true;
            } else {
                $arguments[] = $arg;
            }
        }

        if (!count($arguments)) {
            array_unshift($arguments, 'help');
        }

        $config = new Config(
            [
                'uses' => [
                    'core'     => null,
                    'git'      => null,
                    'php'      => null,
                    'composer' => null,
                    'phpunit'  => null,
                    'phpcs'    => null,
                    'travis'   => null,
                    'npm'      => null,
                    'gulp'     => null,
                    'itiqiti'  => null,
                ],
            ]
        );

        $el = new ExpressionLanguage();

        $expressionService = new ExpressionService($el);
        $s                 = new Service\ConfigService($expressionService);

        $s->load($config);

        $commandNames = array_shift($arguments);

        return $this->executeCommandFromName($input, $output, $commandNames, $arguments, $options, $config, $s);
    }
342692
public function execute($binPath = null, $args = null, $env = null)
    {
        if ($binPath !== null) {
            $this->binPath = $binPath;
        }

        if ($env !== null) {
            $this->env = $env;
        }

        if ($args !== null) {
            $this->args = $args;
        }
        $this->cmd = $this->binPath . static::buildArgs($this->args) . ($this->outputErrors ? ' 2>&1' : '');

        if (isset($this->setUser) || isset($this->setGroup)) {
            if (isset($this->setUser) && isset($this->setGroup) && ($this->setUser !== $this->setGroup)) {
                $this->cmd = 'sudo -g ' . escapeshellarg($this->setGroup) . '  -u ' . escapeshellarg($this->setUser) . ' ' . $this->cmd;
            } else {
                $this->cmd = 'su ' . escapeshellarg($this->setGroup) . ' -c ' . escapeshellarg($this->cmd);
            }
        }

        if ($this->chroot !== '/') {
            $this->cmd = 'chroot ' . escapeshellarg($this->chroot) . ' ' . $this->cmd;
        }

        if ($this->nice !== null) {
            $this->cmd = 'nice -n ' . ((int)$this->nice) . ' ' . $this->cmd;
        }

        $pipesDescr = [
            0 => ['pipe', 'r'], // stdin is a pipe that the child will read from
            1 => ['pipe', 'w'] // stdout is a pipe that the child will write to
        ];

        if (($this->errlogfile !== null) && !$this->outputErrors) {
            $pipesDescr[2] = ['file', $this->errlogfile, 'a']; // @TODO: refactoring
        }

        $this->pd = proc_open($this->cmd, $pipesDescr, $this->pipes, $this->cwd, $this->env);
        if ($this->pd) {
            $this->setFd($this->pipes[1]);
        }

        return $this;
    }
116464
public function runCommand($commandName, array $args = [])
    {
        $application = $this->getApplication();

        $command = $application->find($commandName);

        $arrayInput = new ArrayInput($args);

        $arrayInput->setInteractive(false);

        $command->run($arrayInput, $this->getOutput());
    }
999581
public function executeHello(array $args, array $options = array())
    {
        $name = 'unknown';
        if (empty($args)) {
            $dialog = new Dialog($this->console);
            $name = $dialog->ask('What is your name?', $name);
        } else {
            $name = $args[0];
        }
        $this->writeln(sprintf('hello %s!', $name));
    }
423877
public static function setEnvironment($environmentArg)
    {
        $environmentArg = strtolower(trim($environmentArg));

        $aliases = [
            \Genesis\API\Constants\Environments::STAGING    => [
                'test',
                'testing',
                'staging',
                \Genesis\API\Constants\Environments::STAGING
            ],
            \Genesis\API\Constants\Environments::PRODUCTION => [
                'live',
                'prod',
                'production',
                \Genesis\API\Constants\Environments::PRODUCTION
            ]
        ];

        foreach ($aliases as $environment => $endpointAlias) {
            foreach ($endpointAlias as $alias) {
                if (stripos($environmentArg, $alias) !== false) {
                    return self::$vault['environment'] = $environment;
                }
            }
        }

        throw new \Genesis\Exceptions\InvalidArgument(
            'Invalid Environment'
        );
    }
760432
public function run($args)
	{
		$runner=$this->getCommandRunner();
		$commands=$runner->commands;
		if(isset($args[0]))
			$name=strtolower($args[0]);
		if(!isset($args[0]) || !isset($commands[$name]))
		{
			echo <<<EOD
At the prompt, you may enter a PHP statement or one of the following commands:

EOD;
			$commandNames=array_keys($commands);
			sort($commandNames);
			echo ' - '.implode("\n - ",$commandNames);
			echo <<<EOD


Type 'help <command-name>' for details about a command.

To expand the above command list, place your command class files
under 'protected/commands/shell', or a directory specified
by the 'YIIC_SHELL_COMMAND_PATH' environment variable. The command class
must extend from CConsoleCommand.

EOD;
		}
		else
			echo $runner->createCommand($name)->getHelp();
		return 1;
	}
837942
public function run(...$args): void
    {
        $container = $this->getContainer();
        $instance = $container->get($this->classIdentifier);

        $instance->{$this->callbackMethod}(...$args);
    }
1295619
public function run(array $args)
    {
		if(count($args) < 3) {
            Index::error('Not enough arguments.', 'Usage: eve job random-mail subject=hi&body=hello...');
        }
		
		$data = array();
		
		if(strpos($args[2], '?') === 0) {
			parse_str(substr($args[2], 1), $data);
		} else {
			$data = json_decode($args[2], true);
		}
		
		$namespace = 'Eve';
		
		if(file_exists($this->cwd.'/composer.json')) {
			$json = $this('file', $this->cwd.'/composer.json')->getContent();
			$json = json_decode($json, true);

			if(isset($json['autoload']['psr-4'])
				&& is_array($json['autoload']['psr-4'])
			) {
				foreach($json['autoload']['psr-4'] as $namespace => $path) {
					if(strlen($path) === 0) {
						$namespace = substr($namespace, 0, -1);
						break;
					}
				}
			}
		}
		
		\Eve\Framework\Index::i($this->cwd, $namespace)
			// set default paths
			->defaultPaths()
			// set default database
			->defaultDatabases()
			->job($args[1])
			->setData($data)
			->run();
		
		Index::success('`'.$args[1].'` job has been successfully executed.');
    }
358604
public function main(array $args = array()) {
        Garp_Cli::errorOut('This command is no longer compatible with the AWS Cli tool and should be refactored.');
        return false;
        if (!$this->_usesAmazon()) {
            Garp_Cli::errorOut(
                'Clearly this environment does not ' .
                'use Amazon services. Get outta here!'
            );
            return false;
        }

        $this->_setProfile();

        if (!$this->_profileExists()) {
            $this->_createProfile();
        }
        return parent::main($args);
    }
765935
protected function execute(InputInterface $input, OutputInterface $output)
    {
        // set env through argument --env
        if ($input->hasOption('env')) {
            $env = $input->getOption('env');
            putenv("APP_ENV=$env");
        }

        // call method defined in Command.
        return call_user_func_array([$this, 'handle'], []);
    }
639320
public function run(array $args)
    {
        $command = 'help';

        if(isset($args[1])) {
            $command = $args[1];
        }

        //cradle author/vendor action
        if(strpos($command, '/') !== false) {
            $command = 'package';
            array_splice($args, 1, 0, array($command));
        }

        $class = '\\Cradle\\CommandLine\\'.ucwords($command);

        if(!class_exists($class)) {
            //by default it's an event
            $class = '\\Cradle\\CommandLine\\Event';
            array_splice($args, 1, 0, array('event'));
        }

        array_shift($args);
        $runner = new $class($this->cwd);

        $results = $runner->run($args);

        print PHP_EOL;

        return $results;
    }
1132085
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->requireConfig();

        $utils = new Utils();
        $output->writeln('Starting <fg=blue>Magallanes</>');
        $output->writeln('');

        try {
            $this->runtime->setEnvironment($input->getArgument('environment'));

            if (!$this->runtime->getEnvOption('releases', false)) {
                throw new RuntimeException('Releases are not enabled', 70);
            }

            $output->writeln(sprintf('    Environment: <fg=green>%s</>', $this->runtime->getEnvironment()));
            $this->log(sprintf('Environment: %s', $this->runtime->getEnvironment()));

            if ($this->runtime->getConfigOption('log_file', false)) {
                $output->writeln(sprintf('    Logfile: <fg=green>%s</>', $this->runtime->getConfigOption('log_file')));
            }

            $output->writeln('');

            $hosts = $this->runtime->getEnvOption('hosts');
            if (!is_array($hosts) && !$hosts instanceof \Countable) {
                $hosts = [];
            }
            if (count($hosts) == 0) {
                $output->writeln('No hosts defined');
                $output->writeln('');
            } else {
                $hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');

                foreach ($hosts as $host) {
                    $this->runtime->setWorkingHost($host);

                    // Get List of Releases
                    $cmdListReleases = sprintf('ls -1 %s/releases', $hostPath);

                    /** @var Process $process */
                    $process = $this->runtime->runRemoteCommand($cmdListReleases, false);
                    if (!$process->isSuccessful()) {
                        throw new RuntimeException(sprintf('Unable to retrieve releases from host "%s"', $host), 80);
                    }

                    $releases = [];
                    if (trim($process->getOutput()) != '') {
                        $releases = explode(PHP_EOL, trim($process->getOutput()));
                        rsort($releases);
                    }

                    if (count($releases) == 0) {
                        $output->writeln(sprintf('    No releases available on host <fg=black;options=bold>%s</>:', $host));
                    } else {
                        // Get Current Release
                        $cmdCurrentRelease = sprintf('readlink -f %s/current', $hostPath);

                        /** @var Process $process */
                        $process = $this->runtime->runRemoteCommand($cmdCurrentRelease, false);
                        if (!$process->isSuccessful()) {
                            throw new RuntimeException(sprintf('Unable to retrieve current release from host "%s"', $host), 85);
                        }

                        $currentReleaseId = explode('/', trim($process->getOutput()));
                        $currentReleaseId = $currentReleaseId[count($currentReleaseId) - 1];

                        $output->writeln(sprintf('    Releases on host <fg=black;options=bold>%s</>:', $host));

                        foreach ($releases as $releaseId) {
                            $releaseDate = $utils->getReleaseDate($releaseId);

                            $output->write(sprintf('        Release ID: <fg=magenta>%s</> - Date: <fg=black;options=bold>%s</> [%s]',
                                $releaseId,
                                $releaseDate->format('Y-m-d H:i:s'),
                                $utils->getTimeDiff($releaseDate)
                            ));

                            if ($releaseId == $currentReleaseId) {
                                $output->writeln(' <fg=red;options=bold>[current]</>');
                            } else {
                                $output->writeln('');
                            }
                        }
                    }

                    $this->runtime->setWorkingHost(null);
                    $output->writeln('');
                }
            }
        } catch (RuntimeException $exception) {
            $output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
            $this->statusCode = $exception->getCode();
        }

        $output->writeln('Finished <fg=blue>Magallanes</>');

        return $this->statusCode;
    }