Listen for $argv and run console app

@param  array $argv Arguments
@return mixed
499828
public function listen(array $argv = [])
    {
        $this->climate->description(config('app.description'));
        $this->climate->arguments->add([
            'help' => [
                'prefix' => 'h',
                'longPrefix' => 'help',
                'description' => 'Show help message',
                'noValue' => true
            ],
            'ansi' => [
                'longPrefix' => 'ansi',
                'description' => 'Force ANSI output',
                'noValue' => true
            ],
            'no-ansi' => [
                'longPrefix' => 'no-ansi',
                'description' => 'Disable ANSI output',
                'noValue' => true
            ],
            'env' => [
                'longPrefix' => 'env',
                'description' => 'The environment the command should run under',
            ]
        ]);

        if (empty($argv)) {
            return $this->usage($argv);
        }

        $cmd = array_shift($argv);

        if (array_key_exists($cmd, $this->commands)) {
            $command = $this->commands[$cmd];

            $this->climate->arguments->parse($argv);

            return $this->execute($command, $argv);
        }

        return $this->usage($argv);
    }
174872
public function listen($args = null)
    {
        if ('action' === $this->getModel()->getType()) {
            return do_action($this->getModel()->getIdentifier(), $args);
        }

        return apply_filters($this->getModel()->getIdentifier(), $args);
    }
380529
public function run($args) {
        if (!isset($this->servers)) {
            echo "No server specified in config!";
            exit;
        }

        if (!isset($this->aliases)) {
            echo "No alias defined in config!";
            exit;
        }

        if (!isset($args[2])) {
            $this->getHelp();
            exit;
        }
        $src = $args[0];
        $dest = $args[1];
        $alias = $args[2];
        $file = (isset($args[3])) ? $args[3] : "";

        $path = Yii::getPathOfAlias($this->aliases[$alias]);
        $relativePath = str_replace(Yii::app()->basePath,"",$path);

        $srcUrl = $this->servers[$src].$relativePath."/".$file;
        $destUrl = $this->servers[$dest].$relativePath."/".$file;

        $cmd = "rsync {$this->params} -av ".$srcUrl." ".$destUrl;
        echo "\n".$cmd."\n\n";
        echo "Start rsync of '".$alias."' (".$relativePath."/".$file.") from '".$src."' to '".$dest."'? [Yes|No] ";
        if(!strncasecmp(trim(fgets(STDIN)),'y',1)) {
            system($cmd, $output);
        } else {
            echo "Skipped.\n";
        }
    }
129704
def run(self, argv):
        """"""
        command = argv[0]
        handlers = { 
            'cancel': self.cancel,
            'create': self.create,
            'events': self.events,
            'finalize': self.finalize,
            'list': self.list,
            'pause': self.pause,
            'preview': self.preview,
            'results': self.results,
            'searchlog': self.searchlog,
            'summary': self.summary,
            'perf': self.perf,
            'timeline': self.timeline,
            'touch': self.touch,
            'unpause': self.unpause,
        }
        handler = handlers.get(command, None)
        if handler is None:
            error("Unrecognized command: %s" % command, 2)
        handler(argv[1:])
1062687
public function parse(array $argv): Command
    {
        $this->argv = $argv;

        $command = $this->commandFor($argv);
        $aliases = $this->aliasesFor($command);

        // Eat the cmd name!
        foreach ($argv as $i => $arg) {
            if (\in_array($arg, $aliases)) {
                unset($argv[$i]);

                break;
            }

            if ($arg[0] === '-') {
                break;
            }
        }

        return $command->parse($argv);
    }
372944
protected function parseArgv($argv)
    {
        foreach ($this->argv as $arg) {
            $parts = explode('=', $arg);
            if (! isset($parts[1])) {
                continue;
            }
            $value = $parts[1];
            $key   = strtr($parts[0], [
                '-' => ''
            ]);

            if (array_key_exists($key, $this->supportedArgs)) {
                $this->parsedArgs[$key] = $value;
            }

        }

        return $this;
    }
289368
protected function runCommand(Command $command, array $argv, ConsoleIo $io)
    {
        try {
            return $command->run($argv, $io);
        } catch (StopException $e) {
            return $e->getCode();
        }
    }
48739
public static void main(String argv[]) throws Exception {   
    DnsMonitorSecurityManager.setTheManager();
    AvatarShell shell = null;
    try {
      shell = new AvatarShell();
    } catch (RPC.VersionMismatch v) {
      System.err.println("Version Mismatch between client and server"
          + "... command aborted.");
      System.exit(-1);
    } catch (IOException e) {
      System.err.println("Bad connection to AvatarNode. command aborted.");
      System.exit(-1);
    }

    int res;
    try {
      res = ToolRunner.run(shell, argv);
    } finally {
      shell.close();
    }
    System.exit(res);
  }
557925
def run_from_argv(self, argv):
        
        if (len(argv) > 2 and not argv[2].startswith('-') and
                argv[2] in self.subcommands.keys()):
            subcommand = argv[2]
            klass = self.get_subcommand(subcommand)
            parser = OptionParser(
                prog=argv[0],
                usage=klass.usage('{0} {1}'.format(argv[1], subcommand)),
                version=klass.get_version(), option_list=klass.option_list)
            options, args = parser.parse_args(argv[3:])
            args = [subcommand] + args
        else:
            parser = self.create_parser(argv[0], argv[1])
            options, args = parser.parse_args(argv[2:])

        handle_default_options(options)
        self.execute(*args, **options.__dict__)
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);
        }
    }
714840
public static function main($argc, array $argv = [])
    {
        $self = new self;
        $self->demonstrateReferenceEquality();
        $self->demonstrateValueEquality();
        $self->demonstrateCustomEquality();

        return 0;
    }
1151407
protected function executeDirective($directive, $context, $argv)
    {
        if (!$this->isRegistered($directive)) {
            throw new \RuntimeException(sprintf(
                "Undefined Directive \"%s\" in %s", $directive, $this->source
            ));
        }

        $callback = $this->directives[$directive];

        array_unshift($argv, $context);

        return call_user_func_array($callback, $argv);
    }
421751
public function handleArguments(array $argv): void
    {
        parent::handleArguments($argv);

        if (Get::value('sugaredDebug', $this->arguments, false)) {
            $this->logDebug('Parsed arguments', $this->arguments);
        }

        $this->addListeners();
    }
375461
public function run(array $args, $method='get'){
      $method = strtolower($method);
      $append_echoed_text = Options::get('core.route.append_echoed_text',true);
      static::trigger('start', $this, $args, $method);

      // Call direct befores
      if ( $this->befores ) {
        // Reverse befores order
        foreach (array_reverse($this->befores) as $mw) {
          static::trigger('before', $this, $mw);
          Event::trigger('core.route.before', $this, $mw);
          ob_start();
          $mw_result  = call_user_func($mw);
          $raw_echoed = ob_get_clean();
          if ($append_echoed_text) Response::add($raw_echoed);
          if ( false  === $mw_result ) {
            return [''];
          } else {
            Response::add($mw_result);
          }
        }
      }

      $callback = (is_array($this->callback) && isset($this->callback[$method]))
                  ? $this->callback[$method]
                  : $this->callback;

      if (is_callable($callback) || is_a($callback, "View") ) {
        Response::type( Options::get('core.route.response_default_type', Response::TYPE_HTML) );

        ob_start();
        if (is_a($callback, "View")) {
          // Get the rendered view
          $view_results = (string)$callback;
        } else {
          $view_results = call_user_func_array($callback, $args);
        }
        $raw_echoed   = ob_get_clean();

        if ($append_echoed_text) Response::add($raw_echoed);
        Response::add($view_results);
      }

      // Apply afters
      if ( $this->afters ) {
        foreach ($this->afters as $mw) {
          static::trigger('after', $this, $mw);
          Event::trigger('core.route.after', $this, $mw);
          ob_start();
          $mw_result  = call_user_func($mw);
          $raw_echoed = ob_get_clean();
          if ($append_echoed_text) Response::add($raw_echoed);
          if ( false  === $mw_result ) {
            return [''];
          } else {
            Response::add($mw_result);
          }
        }
      }

      static::trigger('end', $this, $args, $method);
      Event::trigger('core.route.end', $this);

      return [Filter::with('core.route.response', Response::body())];
     }
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;
	}
1353907
protected function parseOption(array $argv, $argNum)
    {
        $arg = $argv[$argNum];
        $argsParsed = 1;
        $isLong = self::isLong($arg);
        $name = substr($arg, $isLong ? 2 : 1);
        // Getting option's value
        if (!isset($argv[$argNum + 1])
            || self::isOption($argv[$argNum + 1])
            || self::isArgumentSeparator($argv[$argNum + 1])
            || self::isClustered($arg)
        ) {
            $value = true;
        } else {
            $value = $argv[$argNum + 1];
            $argsParsed++;
        }
        // Storing the option and its value
        if ($isLong) {
            $this->optionsLong[$name] = $value;
        } else {
            // Short options can be clustered
            $length = strlen($name);
            for ($i = 0; $i < $length; $i++) {
                $this->optionsShort[$name[$i]] = $value;
            }
        }

        return $argsParsed;
    }
219458
public static function parse(array $argv)
    {
        $args = [];
        $options = [];

        for ($i = 0, $num = count($argv); $i < $num; $i++) {
            $arg = $argv[$i];
            if ($arg === '--') {//后缀所有内容都为参数
                $args[] = implode(' ', array_slice($argv, $i + 1));
                break;
            }
            if (substr($arg, 0, 2) === '--') {
                $key = substr($arg, 2);
                $value = true;
                if (($hadValue = strpos($arg, '=')) !== false) {
                    $key = substr($arg, 2, $hadValue - 2);
                    $value = substr($arg, $hadValue + 1);
                }
                if (array_key_exists($key, $options)) {
                    if (!is_array($options[$key])) {
                        $options[$key] = [$options[$key]];
                    }
                    $options[$key][] = $value;
                } else {
                    $options[$key] = $value;
                }
            } else if (substr($arg, 0, 1) === '-') {
                foreach (str_split(substr($arg, 1)) as $key) {
                    $options[$key] = true;
                }
            } else {
                $args[] = $arg;
            }
        }

        return [$args, $options];
    }