运行命令

@param array|null $argv

@return mixed
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);
        }
    }
223597
public function dispatch($argv){
        $name = reset($argv);

        if(!$this->hasCommand($name)){
            throw new \InvalidArgumentException('Command not found');
        }

        // load command
        $command = $this->commands[$name];

        // parse arguments
        $arguments = $command->getArguments();
        $arguments->parse($argv);

        // execute command
        $handler = $command->getHandler();
        if(is_array($handler)){
            $class = $handler[0];
//            if($this->container->has($class)){
//                $this->container->add($class);
//            }
            $obj = $this->container->get($class);
            $handler[0] = $obj;
        }
        call_user_func_array($handler, [$arguments]);
    }
726493
protected function run($args)
    {
        if (!isset($args[0])) {
            return "> Producer: Command required.\n";
        }

        switch (trim($args[0])) {
            case 'init':
                return $this->runInit($args);
            case 'autoload':
                return $this->cmdAutoload($args);
            case 'check':
                return $this->cmdCheck($args);
            case 'test':
                return $this->cmdTest($args);
            case 'clone':
                return $this->cmdClone($args);
            case 'mount':
                return $this->cmdMount($args);
            case 'purge':
                return $this->cmdPurge($args);
            case 'reset':
                return $this->cmdReset($args);
            case 'update':
                return $this->runUpdate($args);
            case 'install':
                return $this->cmdInstall();
            case 'publish':
                return $this->cmdPublish($args);
            case '--version':
                return $this->cmdVersion();
            case '--help':
                return $this->cmdHelp($args);
            default:
                return "> Producer: Undefined '{$args[0]}' command.\n";
        }
    }
618348
public function parse(array $argv = null)
    {
        $this->parser->setFilter($this->filter, $this->all());

        $this->parser->parse($argv);
    }
1282621
public static function run($command = null) {
        $parameters = null;
        if ($command) {
            $parameters = $_SERVER['argv'];

            // 去除命令名
            array_shift($parameters);

            //添加指定命令到参数里
            array_unshift($parameters, $command);
        }
        $input = self::input($parameters);//new Input($parameters);
        $output = self::output();//new Output();
        $exitCode = self::driver()->execute($input,$output);
        exit($exitCode);
    }
657278
public function run(array $args = null)
    {
        global $argv;

        if (isset($argv[1]) && $argv[1] == 'autocomplete' && !isset($argv[2])) {
            $this->setBanner(
                function () {
                    return 0;
                }
            );
            $this->setFooter(
                function () {
                    return 0;
                }
            );
        }

        return parent::run($args);
    }
1311715
public function beforeHandleTask($argv)
    {
        return function(Event $event, Console $console, Dispatcher $dispatcher) use ($argv) {
            //parse parameters
            $parsedOptions = OptionParser::parse($argv);

            $dispatcher->setParams(array(
                'activeTask'  => isset($parsedOptions[0]) ? $parsedOptions[0] : false,
                'activeAction'  => isset($parsedOptions[1]) ? $parsedOptions[1] : false,
                'args'    =>  count($parsedOptions) > 2 ? array_slice($parsedOptions, 2) : []
            ));
        };
    }
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;
	}
865931
public static function get(string ... $argv)
    {
        // 动态参数列表
        $args = count($argv);

        // 缓存
        static $all = [];

        // 一个参数都未给出
        if ($args < 1) {
            throw new ConfigException('请求配置时缺少参数', ConfigException::MISS_ARGUMENT);
        }

        // 第一个参数是配置文件名
        $file = $argv[0];

        // 如果尚未获取,则获取
        if (!isset($all[$file])) {
            $all[$file] = self::readFile($file);
        }

        // 根据请求参数,获取子项
        $config = $all[$file];

        // 配置项不是数组
        if (!is_array($config)) {
            throw new ConfigException('配置文件内容必须是数组', ConfigException::CONTENT_NOT_ARRAY);
        }

        // 根据函数参数,获取继续的子项
        for ($i = 1; $i < $args; $i++) {
            $itemName = $argv[$i];

            // 没有指定的配置项
            if (!isset($config[$itemName])) {
                return null;
            }

            $config = $config[$itemName];
        }

        return $config;
    }
39300
public function parseParams($argv)
    {
        if (is_string($argv)) {
            $argv = gplcart_string_explode_whitespace($argv);
        }

        array_shift($argv);

        $out = array();
        for ($i = 0, $j = count($argv); $i < $j; $i++) {

            $key = null;
            $arg = $argv[$i];

            if (substr($arg, 0, 2) === '--') {

                $pos = strpos($arg, '=');

                if ($pos === false) {
                    $key = substr($arg, 2);
                    if ($i + 1 < $j && $argv[$i + 1][0] !== '-') {
                        $value = $argv[$i + 1];
                        $i++;
                    } else {
                        $value = isset($out[$key]) ? $out[$key] : true;
                    }

                    $out[$key] = $value;
                    continue;
                }

                $key = substr($arg, 2, $pos - 2);
                $value = substr($arg, $pos + 1);
                $out[$key] = $value;
                continue;
            }

            if (substr($arg, 0, 1) === '-') {

                if (substr($arg, 2, 1) === '=') {
                    $key = substr($arg, 1, 1);
                    $value = substr($arg, 3);
                    $out[$key] = $value;
                    continue;
                }

                foreach (str_split(substr($arg, 1)) as $char) {
                    $key = $char;
                    $value = isset($out[$key]) ? $out[$key] : true;
                    $out[$key] = $value;
                }

                if ($i + 1 < $j && $argv[$i + 1][0] !== '-') {
                    $out[$key] = $argv[$i + 1];
                    $i++;
                }

                continue;
            }

            $value = $arg;
            $out[] = $value;
        }

        return $out;
    }
395595
public function redirect($page = null, $arg = array())
    {
        $url = $this->app->url($page, $arg);

        return $this->univ()->_fn('redirect', array($url));
    }
189624
public function
	Query($Format,$Argv=false) {
	/*//
	@return Nether\Database\Result
	//*/

		if($Argv && !is_array($Argv) && !is_object($Argv))
		throw new Nether\Database\Error\InvalidQueryInput;

		// convert to an object if not an object. this would theoretically
		// allow you to supply objects with magic methods.

		if(!is_object($Argv))
		$Argv = (object)$Argv;

		////////
		// build a dataset that directly maps to the bound parameters in the
		// query with no unused values.

		$SQL = (is_object($Format))?("{$Format}"):($Format);
		$Dataset = [];

		$this->Query_BuildDataset($SQL,$Argv,$Dataset);
		$this->Query_ExpandDataset($SQL,$Argv,$Dataset);

		////////
		// and then perform the query.

		$QueryTime = microtime(true);

		if(!($Statement = $this->Driver->Prepare($SQL)))
		throw new Nether\Database\Error\QueryPrepareFailure;

		$Result = new Database\Result($this,$Statement,$Dataset);
		if(Nether\Option::Get('nether-database-query-log')) {
			static::$QueryLog[] = (object)[
				'Time' => round($Result->GetTime(),4),
				'Query' => $Result->GetQuery(),
				'Input' => $Result->GetArgs(),
				'Count' => $Result->GetCount(),
				'Trace' => static::GetDebugTrace()
			];
		}

		static::$QueryTime += microtime(true) - $QueryTime;
		static::$QueryCount++;

		return $Result;
	}
760578
public function
	Run($cmd=null) {
	/*//
	@argv string HandlerName
	@argv array CommandArgumentList

	if given a string it will execute the handler defined under as that name.
	if given an array then it will process that array as though it was the
	_SERVER['argv'] data and execute as if that was the original command line
	given to the object creation.
	//*/

		$restore = false;
		$return = 0;

		////////
		////////

		if(is_array($cmd)) {
			// rewrite our input and option data with this subcommand
			// that was given to us. execute as though this array defined
			// the original command input.

			$restore = [ 'Inputs'=>$this->Inputs, 'Options'=>$this->Options ];

			$data = static::ParseCommandArgs($cmd,false);
			$this->Inputs = $data['Inputs'];
			$this->Options = $data['Options'];

			$cmd = $this->GetInputs();
		}

		////////
		////////

		if(!$cmd && !($cmd = $this->GetInput(1))) {
			if(!$this->DefaultHandlerName) {
				echo "No input provided.", PHP_EOL;
				return static::ErrorNoInput;

			}

			$cmd = [$this->DefaultHandlerName];
		}

		else {
			$cmd = $this->GetInputs();
		}

		////////
		////////

		$Commanded = FALSE;

		foreach($cmd as $cur) {
			$method = static::GetMethodFromCommand($cur);
			try {
				$return = $this->Run_ByMethod($method);
				$Commanded = TRUE;
			}
			catch(ClientHandlerException $e) {
				try {
					$return = $this->Run_ByCallable($cur);
					$Commanded = TRUE;
				}
				catch(ClientHandlerException $e) { }
			}

			if($Commanded && !$this->ChainCommands)
			break;
		}

		if(!$Commanded) {
			echo "no handler or method found for {$cur}", PHP_EOL;
			return static::ErrorNoHandler;
		}

		////////
		////////

		if($restore) {
			// restore the original input data before continuing on so that
			// we could continue processing the cli input data if needed.
			$this->Inputs = $restore['Inputs'];
			$this->Options = $restore['Options'];
		}

		return $return;
	}
624998
protected function doRun($method, array $args=[]) {
		ob_start();
		$result = call_user_func_array($method, array_merge([$this], $args));
		$controllerBuffer =  ob_get_clean();

		if($result !== null)
			return $result;
		if($controllerBuffer)
			return $controllerBuffer;
		return null;
	}
32767
public function getArgs(int $argc, array $argv)
    {
        if ($argc == 1) {
            Output::displayAsGreen(
                "Welcome to the Framework Console Manager\n".
                "I noticed that you didn't enter any parameters.\n".
                "For more information, you can use the help command to get a command list."
            );
        }

        $c = $this->searchCommand($argv[1]);
        if (empty($c)) {
            CoreManager::setCurrentModule("Error");
            $predict = (PredictionManager::parsePredict($argv[1]));
            if (empty($predict)) {
                Output::displayAsError("Command not found.\n".
                    "For more information, you can use the [help] command to get a command list.");
            } else {
                Output::displayAsError("Input [".$argv[1]."] is ambigus.\n".
                    "To get command list, use [help] keyword.\n\n".
                    PredictionManager::structMessage($predict));
            }
        }

        $p = ParseManager::parse($argv);
        $ref = new Reflex();
        $ref->__simple($c['class'], $p);
    }
737015
public function run($args)
    {
        list($action, $options, $args) = $this->resolveRequest($args);

        foreach ($options as $key => $value) {
            if (property_exists($this, $key)) {
                $this->$key = $value;
            }
        }

        $binPath = $this->resolveBinPath();
        $options = $this->normalizeOptions($this->options);
        $database = $this->resolveDatabaseName();
        $dumpPath = $this->resolveDumpPath();

        return $this->process(
            "$binPath $options $database",
            array(
                self::DESCRIPTOR_STDIN  => array('pipe', 'r'),
                self::DESCRIPTOR_STDOUT => array('file', $dumpPath, 'w'),
                self::DESCRIPTOR_STDERR => array('pipe', 'w'),
            )
        );
    }
1325453
public static function argv(string $variable, $default = null) {
		return isset(self::$_argv[$variable])
			? self::$_argv[$variable]
			: $default;
	}