Execute the action.
@param array $args command line parameters specific for this command
@return integer|null non zero application exit code for help or null on success
168806
public function run($args)
	{
		if(!isset($args[0],$args[1]))
		{
			echo "Error: both model class and view name are required.\n";
			echo $this->getHelp();
			return 1;
		}
		$scenario=isset($args[2]) ? $args[2] : '';
		$modelClass=Yii::import($args[0],true);
		$model=new $modelClass($scenario);
		$attributes=$model->getSafeAttributeNames();

		$templatePath=$this->templatePath===null?YII_PATH.'/cli/views/shell/form':$this->templatePath;
		$viewPath=Yii::getPathOfAlias($args[1]);
		$viewName=basename($viewPath);
		$viewPath.='.php';
		$params=array(
			'modelClass'=>$modelClass,
			'viewName'=>$viewName,
			'attributes'=>$attributes,
		);
		$list=array(
			basename($viewPath)=>array(
				'source'=>$templatePath.'/form.php',
				'target'=>$viewPath,
				'callback'=>array($this,'generateForm'),
				'params'=>$params,
			),
		);

		$this->copyFiles($list);

		$actionFile=$templatePath.'/action.php';
		if(!is_file($actionFile))  // fall back to default ones
			$actionFile=YII_PATH.'/cli/views/shell/form/action.php';

		echo "The following form view has been successfully created:\n";
		echo "\t$viewPath\n\n";
		echo "You may use the following code in your controller action:\n\n";
		echo $this->renderFile($actionFile,$params,true);
		echo "\n";
	}
1147960
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));
        }

        //if command is package
        if ($command === 'package'
            && (//and no package was defined
                !isset($args[2])
                || strpos($args[2], '/') === false
            )
        ) {
            $command = 'event';
            array_splice($args, 1, 0, ['event']);
        }

        $class = sprintf(self::COMMAND_CLASS, ucwords($command));

        if (!class_exists($class)) {
            //by default it's an event
            $class = sprintf(self::COMMAND_CLASS, 'Event');
            array_splice($args, 1, 0, array('event'));
        }

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

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

        self::output(PHP_EOL);

        return $results;
    }
719228
public function run($args)
    {
        foreach ($this->permissions as $dir => $config) {
            $path = $this->basePath . '/' . $dir;
            if (file_exists($path)) {
                try {
                    if (isset($config['user'])) {
                        $this->changeOwner($path, $config['user']);
                    }
                    if (isset($config['group'])) {
                        $this->changeGroup($path, $config['group']);
                    }
                    if (isset($config['mode'])) {
                        $this->changeMode($path, $config['mode']);
                    }
                } catch(CException $e) {
                    echo $this->formatError($e->getMessage())."\n";
                }
            } else {
                echo sprintf("Failed to change permissions for %s. File does not exist!\n", $path);
            }
        }
        echo "Permissions successfully changed.\n";
        return 0;
    }
327644
public function executeAll(...$args)
    {
        if ($this->isEmpty()) {
            return 0;
        }
        $n = 0;
        do {
            $cb = $this->extract();
            if ($cb) {
                $cb(...$args);
                ++$n;
            }
        } while (!$this->isEmpty());
        return $n;
    }
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;
    }
565119
public function main(array $args = array()) {
        Garp_Cli::lineOut('Welcome to the Garp interactive shell.', Garp_Cli::YELLOW);
        Garp_Cli::lineOut('Use Ctrl-C to quit.');

        $this->_setErrorHandler();
        $this->_tick();
    }
105917
private function cmdPurge($args)
    {
        $cmd = new PurgeCommand($this->cwd);

        return $cmd->run(array_slice($args, 1));
    }
668861
public function execute(array $args = [], array $options = [])
    {
        foreach ($this->sequence as $command) {
            $command->setConfig($this->getConfig());
            $command->setConfigService($this->getConfigService());
            if ($this->hasOutput() && method_exists($command, 'setOutput')) {
                $command->setOutput($this->getOutput());
            }
            if ($this->hasInput() && method_exists($command, 'setInput')) {
                $command->setInput($this->getInput());
            }
            $command->execute($args, $options);
        }
    }
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();
	}
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;
    }
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);
    }
553671
public function execute(array $argv = [])
    {
        if (empty($argv)) {
            return $this->help();
        }

        $cmd = array_shift($argv);
        if (isset($this->commands[$cmd])) {
            return $this->commands[$cmd]->initialize($argv, $this);
        }

        return $this->help($argv);
    }
400814
public function execute(array $args, array $options = [])
    {
        $rootDir = null;
        if (isset($options['root-dir']) && !empty($options['root-dir'])) {
            $rootDir = $options['root-dir'];
        }
        StaticResource::createSymbolicLink($rootDir);
    }
1310909
public function run(array $args)
    {
        CommandLine::info('Usage: `cradle package <vendor/package> <command>`  - Runs a package event');
        CommandLine::info('Usage: `cradle <vendor/package> <command>`          - Runs a package event');
        CommandLine::info('Usage: `cradle event <event name> <json|query>`     - Runs an event');
        CommandLine::info('Usage: `cradle <event name> <json|query>`           - Runs an event');

        //also call the event
        $class = sprintf(CommandLine::COMMAND_CLASS, 'Event');
        array_splice($args, 1, 0, array('help'));
        $runner = new $class($this->cwd);
        return $runner->run($args);
    }
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);
    }
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());
    }
809752
public static function exec($args, $context)
    {
        $argc = count($args);
        $first = array_shift($args);
        $first = $context->resolve($first);
        switch ($argc) {
            case 1 :
                return $first;
            case 2 :
                if (is_array($first) && isset($first['operator']) && $first['operator'] == 'not') {
                    $operant = array_shift($args);
                    $operant = $context->resolve($operant);

                    return !($operant);
                }
            case 3 :
                list($op, $right) = $args;
                $right = $context->resolve($right);

                return call_user_func(array('Evaluator', $op['operator']), $first, $right);
            default:
                return false;
        }
    }