Execute the action.
@param array $args command line parameters specific for this command
@return integer non zero application exit code for help
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;
	}
1265693
public function execute(array $args, array $options = [])
    {
        $this->bootstrap($args, $options);

        // get the seed path from the config
        $path = $this->getConfig()->getSeedPath();

        if (!file_exists($path)) {
            $ask = new Dialog();
            if ($ask->confirm(Colour::colour('Create seeds directory?', [Colour::RED, Colour::HIGHLIGHT]))) {
                mkdir($path, 0755, true);
            }
        }

        $this->verifySeedDirectory($path);
        $path = realpath($path);

        $className = $args[0];

        if (!Util::isValidPhinxClassName($className)) {
            throw new \InvalidArgumentException(sprintf(
                'The seed class name "%s" is invalid. Please use CamelCase format',
                $className
            ));
        }

        // Compute the file path
        $filePath = $path . DIRECTORY_SEPARATOR . $className . '.php';

        if (is_file($filePath)) {
            throw new \InvalidArgumentException(sprintf(
                'The file "%s" already exists',
                basename($filePath)
            ));
        }

        // inject the class names appropriate to this seeder
        $contents = file_get_contents($this->getSeedTemplateFilename());
        $classes = [
            '$useClassName' => 'Phinx\Seed\AbstractSeed',
            '$className' => $className,
            '$baseClassName' => 'AbstractSeed',
        ];
        $contents = strtr($contents, $classes);

        if (false === file_put_contents($filePath, $contents)) {
            throw new \RuntimeException(sprintf(
                'The file "%s" could not be written to',
                $path
            ));
        }

        Output::writeln('using seed base class ' . $classes['$useClassName']);
        Output::writeln('created ' . str_replace(Cml::getApplicationDir('secure_src'), '{secure_src}', $filePath));
    }
1163882
private static function run(array $arguments)
	{
		// Unwind the args, figure out which ones were passed in as an array
		self::$stdin = null;
		$closureOut = false;
		foreach ($arguments as $k => $argument) {
			// If it's being passed in as an object, then pipe into stdin
			if (\is_object($argument)) {
				// If it's a anonymous function, then push stdout into it
				if ($argument instanceof \Closure) {
					$closureOut = $argument;
				} else {
					self::$stdin = (string) $argument;
				}
				unset($arguments[$k]);
			} elseif (\is_array($argument)) {
				if (Arrays::isAssoc($argument)) {
					// Ok, so we're passing in arguments
					$output = '';
					foreach ($argument as $key => $val) {
						if ($output !== '') {
							$output .= ' ';
						}
						// If you pass 'false', it'll ignore the arg altogether
						if ($val !== false) {
							// Figure out if it's a long or short commandline arg
							if (\strlen($key) === 1) {
								$output .= '-';
							} else {
								$output .= '--';
							}
							$output .= $key;
							// If you just pass in 'true', it'll just add the arg
							if ($val !== true) {
								$output .= ' ' . \escapeshellarg($val);
							}
						}
					}
					$arguments[$k] = $output;
				} else {
					// We're passing in an array, but it's not --key=val style
					$arguments[$k] = \implode(' ', $argument);
				}
			}
		}
		$shell = \implode(' ', $arguments);

		// Prepend the path
		if (\stripos(PHP_OS, 'win') !== 0) {
			$parts = \explode(' ', $shell);
			$parts[0] = \exec('which ' . $parts[0]);
			if ($parts[0] !== '') {
				$shell = \implode(' ', $parts);
			}
		}

		$descriptor_spec = [
			0 => ['pipe', 'r'], // Stdin
			1 => ['pipe', 'w'], // Stdout
			2 => ['pipe', 'w'] // Stderr
		];
		$process = \proc_open($shell, $descriptor_spec, $pipes);
		if (\is_resource($process)) {
			\fwrite($pipes[0], self::$stdin);
			\fclose($pipes[0]);
			$output = '';
			while (!\feof($pipes[1])) {
				$stdout = \fgets($pipes[1], 1024);
				if ($stdout === '') {
					break;
				}

				echo $stdout;

				if ($closureOut instanceof \Closure) {
					$closureOut($stdout);
				}
				$output .= $stdout;
			}
			$error_output = \trim(\stream_get_contents($pipes[2]));
			if (self::$displayStderr) {
				echo $error_output;
			}
			self::$output = $output;
			\fclose($pipes[1]);
			\fclose($pipes[2]);
			$return_value = \proc_close($process);
			if ($return_value !== 0) {
				throw new ShellException($error_output, $return_value);
			}
		} else {
			throw new ShellException('Process failed to spawn');
		}
	}
1270570
private function executeMethod($method, $args = [])
    {
        if (method_exists($this, $method)) {
            return call_user_func_array([$this, $method], $args);
        }
    }
105917
private function cmdPurge($args)
    {
        $cmd = new PurgeCommand($this->cwd);

        return $cmd->run(array_slice($args, 1));
    }
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;
    }
191090
public function run(array $argv = null)
    {
        try {
            if ($argv === null) {
                $argv = isset($_SERVER['argv']) ? array_slice($_SERVER['argv'], 1) : [];
            }

            list($args, $options) = Input::parse($argv);

            $command = count($args) ? array_shift($args) : 'help';

            if (!isset($this->commands[$command])) {
                throw new \InvalidArgumentException("Command '$command' does not exist");
            }

            isset($options['no-ansi']) && Colour::setNoAnsi();
            if (isset($options['h']) || isset($options['help'])) {
                $help = new Help($this);
                $help->execute([$command]);
                exit(0);
            }

            $command = explode('::', $this->commands[$command]);

            return call_user_func_array([new $command[0]($this), isset($command[1]) ? $command[1] : 'execute'], [$args, $options]);
        } catch (\Exception $e) {
            Output::writeException($e);
            exit(1);
        }
    }
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());
    }
1112267
public function run($args)
	{
		if(!isset($args[0]))
			$args[0]='index.php';
		$entryScript=isset($args[0]) ? $args[0] : 'index.php';
		if(($entryScript=realpath($args[0]))===false || !is_file($entryScript))
			$this->usageError("{$args[0]} does not exist or is not an entry script file.");

		// fake the web server setting
		$cwd=getcwd();
		chdir(dirname($entryScript));
		$_SERVER['SCRIPT_NAME']='/'.basename($entryScript);
		$_SERVER['REQUEST_URI']=$_SERVER['SCRIPT_NAME'];
		$_SERVER['SCRIPT_FILENAME']=$entryScript;
		$_SERVER['HTTP_HOST']='localhost';
		$_SERVER['SERVER_NAME']='localhost';
		$_SERVER['SERVER_PORT']=80;

		// reset context to run the web application
		restore_error_handler();
		restore_exception_handler();
		Yii::setApplication(null);
		Yii::setPathOfAlias('application',null);

		ob_start();
		$config=require($entryScript);
		ob_end_clean();

		// oops, the entry script turns out to be a config file
		if(is_array($config))
		{
			chdir($cwd);
			$_SERVER['SCRIPT_NAME']='/index.php';
			$_SERVER['REQUEST_URI']=$_SERVER['SCRIPT_NAME'];
			$_SERVER['SCRIPT_FILENAME']=$cwd.DIRECTORY_SEPARATOR.'index.php';
			Yii::createWebApplication($config);
		}

		restore_error_handler();
		restore_exception_handler();

		$yiiVersion=Yii::getVersion();
		echo <<<EOD
Yii Interactive Tool v1.1 (based on Yii v{$yiiVersion})
Please type 'help' for help. Type 'exit' to quit.
EOD;
		$this->runShell();
	}
631846
public function run($args)
    {
        if (!isset($args[0]) || !$args[0]) {
            return $this->exec('check', [$this->cwd]);
        }

        $name = trim($args[0]);
        if (is_dir($path = $this->cwd.'/repository/'.$name)) {
            return $this->exec('check', [$path]);
        }

        return $this->error('Required project name.');
    }
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));
    }
945496
public function main(array $args = array()) {
        $publicMethods = $this->getPublicMethods();
        if (!array_key_exists(0, $args)) {
            if (in_array('help', $publicMethods)) {
                $args[0] = 'help';
            } else {
                Garp_Cli::errorOut(
                    "No method selected. Available methods: \n " .
                    implode("\n ", $publicMethods)
                );
                return false;
            }
        }

        $methodName = $args[0];
        if (!in_array($methodName, $publicMethods)) {
            Garp_Cli::errorOut('Unknown command \'' . $methodName . '\'');
            return false;
        }
        unset($args[0]);
        $args = $this->_remapArguments($args);
        if (!$this->_validateArguments($methodName, $args)) {
            // Note, _validateArguments also provides the CLI feedback
            return false;
        }
        $result = call_user_func_array(array($this, $methodName), array($args));
        return $result;
    }
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);
    }
75202
protected function handleArgs(array $args) {
        $groupedArgs = $this->argumentsParser->group($args);
        list($groupedArgs, $continue) = $this->runGlobalCommands($groupedArgs);

        if ($continue === false) {
            return;
        }

        try {
            list($command, $groupedArgs) = $this->argumentsMatcher
                ->matchCommands($this->getNotGlobalCommands(), $groupedArgs);
            $command = clone $command;
            $this->runCommand($command);
        } catch (MissingCommandNameException $ex) {
            array_unshift($args, $this->getDefaultCommandName());
            $this->parseArgs($args);
        } catch (Exception $ex) {
            if ($this->getCatchErrors()) {
                $widget = new ExceptionWidget($this->input, $this->output);
                $widget->render($ex);
            } else {
                throw $ex;
            }
        }
    }
892528
public function execute(...$arguments)
    {
        $options = $this->getOptions();
        if ($options->version) {
            $this->logger->writeln($this->name() . ' - ' . static::VERSION);
            $this->logger->writeln('console core: ' . static::CORE_VERSION);

            return;
        }

        // show list and help by default
        $help = $this->getCommand('help');
        $help->setOptions($options);
        if ($help || $options->help) {
            $help->executeWrapper($arguments);

            return;
        }

        throw new CommandNotFoundException($this, 'help');
    }
634350
public function execute(array $args, array $options = [])
    {
        $this->bootstrap($args, $options);

        $format = isset($options['format']) ? $options['format'] : $options['f'];

        if (null !== $format) {
            Output::writeln('using format ' . $format);
        }

        $this->getManager()->printStatus($format);
    }
1151736
public function execute(array $args, array $options = [])
    {
        $this->bootstrap($args, $options);

        $version = isset($options['target']) ? $options['target'] : $options['t'];
        $removeAll = isset($options['remove-all']) ? $options['remove-all'] : $options['r'];

        if ($version && $removeAll){
            throw new \InvalidArgumentException('Cannot toggle a breakpoint and remove all breakpoints at the same time.');
        }

        // Remove all breakpoints
        if ($removeAll){
            $this->getManager()->removeBreakpoints();
        } else {
            // Toggle the breakpoint.
            $this->getManager()->toggleBreakpoint($version);
        }
    }