Process a command line switch which has an argument.

@param int   $i
@param array $argv

@return int
433379
function handleswitch($i, $argv)
    {
        $lv = 0;
        $dv = 0.0;
        $sv = $end = $cp = '';
        $j; // int
        $errcnt = 0;
        $cp = strstr($argv[$i], '=');
        if (!$cp) {
            throw new Exception('INTERNAL ERROR: handleswitch passed bad argument, no "=" in arg');
        }
        $argv[$i] = substr($argv[$i], 0, strlen($argv[$i]) - strlen($cp));
        if (!isset(self::$_options[$argv[$i]])) {
            throw new Exception('Command line syntax error: undefined option "' .  $argv[$i] .
                $cp . '"');
        }
        $cp = substr($cp, 1);
        switch (self::$_options[$argv[$i]]['type']) {
        case self::OPT_FLAG:
        case self::OPT_FFLAG:
            throw new Exception('Command line syntax error: option requires an argument "' .
                $argv[$i] . '=' . $cp . '"');
        case self::OPT_DBL:
        case self::OPT_FDBL:
            $dv = (double) $cp;
            break;
        case self::OPT_INT:
        case self::OPT_FINT:
            $lv = (int) $cp;
            break;
        case self::OPT_STR:
        case self::OPT_FSTR:
            $sv = $cp;
            break;
        }
        switch(self::$_options[$argv[$i]]['type']) {
        case self::OPT_FLAG:
        case self::OPT_FFLAG:
            break;
        case self::OPT_DBL:
            $this->{self::$_options[$argv[$i]]['arg']} = $dv;
            break;
        case self::OPT_FDBL:
            $this->{self::$_options[$argv[$i]]['arg']}($dv);
            break;
        case self::OPT_INT:
            $this->{self::$_options[$argv[$i]]['arg']} = $lv;
            break;
        case self::OPT_FINT:
            $this->{self::$_options[$argv[$i]]['arg']}($lv);
            break;
        case self::OPT_STR:
            $this->{self::$_options[$argv[$i]]['arg']} = $sv;
            break;
        case self::OPT_FSTR:
            $this->{self::$_options[$argv[$i]]['arg']}($sv);
            break;
        }
        return 0;
    }
210841
public function parseArgv(array $argv = null, $strict = true) {
        if ( ! is_array($argv)) {
            global $argv;
        }

        return $this->parseArgs(array_slice($argv, 1), $strict);
    }
1002855
public function handleList(Args $args, IO $io)
    {
        $modules = $this->getSelectedModules($args);

        if ($args->isOptionSet('format')) {
            $this->printModulesWithFormat($io, $modules, $args->getOption('format'));
        } else {
            $this->printModulesByState($io, $modules, $this->getSelectedStates($args));
        }

        return 0;
    }
1252725
function processArgv(argv) {
  let command = getCommand(argv);
  let isInternalCommand = true;

  logger.info(`SKY UX processing command ${command}`);

  switch (command) {
    case 'version':
      require('./lib/version').logVersion(argv);
      break;
    case 'new':
      require('./lib/new')(argv);
      break;
    case 'help':
      require('./lib/help')(argv);
      break;
    case 'install':
      require('./lib/install')(argv);
      break;
    default:
      isInternalCommand = false;
  }

  invokeCommand(command, argv, isInternalCommand);
}
1219133
public static void main(String argv[])
    {
        String srcFile = "randam_orig.png";
        try
        {
            System.out.println("Reading: "+srcFile);
            BufferedImage src = ImageIO.read(new File(srcFile));
            ImageScale3x scaler = new ImageScale3x(src);
            BufferedImage out = scaler.getScaledImage();

            String outFile = srcFile.substring(0,srcFile.length()-4);
            outFile += "3x";
            outFile += ".png";
            System.out.println("Writing: "+outFile);
            ImageIO.write(out,"PNG",new File(outFile));
        } 
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
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);
        }
    }
849938
public function main(array $argv)
    {
        // @codeCoverageIgnoreStart
        // We cannot easily test this, so we'll skip it. Pretty basic anyway.

        if (!$this->stderr) {
            $this->stderr = fopen('php://stderr', 'w');
        }
        if (!$this->stdout) {
            $this->stdout = fopen('php://stdout', 'w');
        }
        if (!$this->stdin) {
            $this->stdin = fopen('php://stdin', 'r');
        }

        // @codeCoverageIgnoreEnd

        try {
            list($options, $positional) = $this->parseArguments($argv);

            if (isset($options['q'])) {
                $this->quiet = true;
            }
            $this->log($this->colorize('green', 'sabre/vobject ').$this->colorize('yellow', Version::VERSION));

            foreach ($options as $name => $value) {
                switch ($name) {
                    case 'q':
                        // Already handled earlier.
                        break;
                    case 'h':
                    case 'help':
                        $this->showHelp();

                        return 0;
                        break;
                    case 'format':
                        switch ($value) {
                            // jcard/jcal documents
                            case 'jcard':
                            case 'jcal':

                            // specific document versions
                            case 'vcard21':
                            case 'vcard30':
                            case 'vcard40':
                            case 'icalendar20':

                            // specific formats
                            case 'json':
                            case 'mimedir':

                            // icalendar/vcad
                            case 'icalendar':
                            case 'vcard':
                                $this->format = $value;
                                break;

                            default:
                                throw new InvalidArgumentException('Unknown format: '.$value);
                        }
                        break;
                    case 'pretty':
                        if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
                            $this->pretty = true;
                        }
                        break;
                    case 'forgiving':
                        $this->forgiving = true;
                        break;
                    case 'inputformat':
                        switch ($value) {
                            // json formats
                            case 'jcard':
                            case 'jcal':
                            case 'json':
                                $this->inputFormat = 'json';
                                break;

                            // mimedir formats
                            case 'mimedir':
                            case 'icalendar':
                            case 'vcard':
                            case 'vcard21':
                            case 'vcard30':
                            case 'vcard40':
                            case 'icalendar20':

                                $this->inputFormat = 'mimedir';
                                break;

                            default:
                                throw new InvalidArgumentException('Unknown format: '.$value);
                        }
                        break;
                    default:
                        throw new InvalidArgumentException('Unknown option: '.$name);
                }
            }

            if (0 === count($positional)) {
                $this->showHelp();

                return 1;
            }

            if (1 === count($positional)) {
                throw new InvalidArgumentException('Inputfile is a required argument');
            }

            if (count($positional) > 3) {
                throw new InvalidArgumentException('Too many arguments');
            }

            if (!in_array($positional[0], ['validate', 'repair', 'convert', 'color'])) {
                throw new InvalidArgumentException('Uknown command: '.$positional[0]);
            }
        } catch (InvalidArgumentException $e) {
            $this->showHelp();
            $this->log('Error: '.$e->getMessage(), 'red');

            return 1;
        }

        $command = $positional[0];

        $this->inputPath = $positional[1];
        $this->outputPath = isset($positional[2]) ? $positional[2] : '-';

        if ('-' !== $this->outputPath) {
            $this->stdout = fopen($this->outputPath, 'w');
        }

        if (!$this->inputFormat) {
            if ('.json' === substr($this->inputPath, -5)) {
                $this->inputFormat = 'json';
            } else {
                $this->inputFormat = 'mimedir';
            }
        }
        if (!$this->format) {
            if ('.json' === substr($this->outputPath, -5)) {
                $this->format = 'json';
            } else {
                $this->format = 'mimedir';
            }
        }

        $realCode = 0;

        try {
            while ($input = $this->readInput()) {
                $returnCode = $this->$command($input);
                if (0 !== $returnCode) {
                    $realCode = $returnCode;
                }
            }
        } catch (EofException $e) {
            // end of file
        } catch (\Exception $e) {
            $this->log('Error: '.$e->getMessage(), 'red');

            return 2;
        }

        return $realCode;
    }
1335189
public static void main(String argv[]) throws Exception {
    try {
      Configuration conf = new Configuration();
      UtilizationReporter utilizationReporter = 
              new UtilizationReporter(conf);
      utilizationReporter.start();
    } catch (Throwable e) {
      System.err.println(e);
      LOG.error(StringUtils.stringifyException(e));
      System.exit(-1);
    }
  }
575947
protected function validateArguments(array $argv = null)
    {
        $argc = count($argv);

        if (1 == $argc && is_array($argv[0])) {
            return $argv[0];
        }

        if (2 == $argc) {
            if (is_array($argv[0]) && (is_numeric($argv[1]) || is_null($argv[1]) || is_string($argv[1]))) {
                $argv[0][] = $argv[1];

                return $argv[0];
            }

            if ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1]))) {
                return $argv;
            }
        }

        if (3 == $argc) {
            if ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1])) && (is_numeric($argv[2]) || is_null($argv[2]) || is_string($argv[2]))) {
                return $argv;
            }
        }

        array_walk($argv, function (&$value) {
            if (is_array($value)) {
                $value = 'Array';
            } else {
                $value = sprintf('"%s"', $value);
            }
        });

        throw new InvalidValueException(sprintf('Invalid parameters passed to %s::%s: %s', get_class($this), '__construct', implode(', ', $argv)));
    }
618348
public function parse(array $argv = null)
    {
        $this->parser->setFilter($this->filter, $this->all());

        $this->parser->parse($argv);
    }
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) : []
            ));
        };
    }
1014914
def process_command_line(argv):
    
    setup = {}
    for handler in ACCEPTED_ARG_HANDLERS:
        setup[handler.arg_name] = handler.default_val
    setup['file'] = ''
    setup['qt-support'] = ''

    i = 0
    del argv[0]
    while i < len(argv):
        handler = ARGV_REP_TO_HANDLER.get(argv[i])
        if handler is not None:
            handler.handle_argv(argv, i, setup)

        elif argv[i].startswith('--qt-support'):
            # The --qt-support is special because we want to keep backward compatibility:
            # Previously, just passing '--qt-support' meant that we should use the auto-discovery mode
            # whereas now, if --qt-support is passed, it should be passed as --qt-support=<mode>, where
            # mode can be one of 'auto', 'none', 'pyqt5', 'pyqt4', 'pyside'.
            if argv[i] == '--qt-support':
                setup['qt-support'] = 'auto'

            elif argv[i].startswith('--qt-support='):
                qt_support = argv[i][len('--qt-support='):]
                valid_modes = ('none', 'auto', 'pyqt5', 'pyqt4', 'pyside')
                if qt_support not in valid_modes:
                    raise ValueError("qt-support mode invalid: " + qt_support)
                if qt_support == 'none':
                    # On none, actually set an empty string to evaluate to False.
                    setup['qt-support'] = ''
                else:
                    setup['qt-support'] = qt_support
            else:
                raise ValueError("Unexpected definition for qt-support flag: " + argv[i])

            del argv[i]

        elif argv[i] == '--file':
            # --file is special because it's the last one (so, no handler for it).
            del argv[i]
            setup['file'] = argv[i]
            i = len(argv) # pop out, file is our last argument

        elif argv[i] == '--DEBUG':
            from pydevd import set_debug
            del argv[i]
            set_debug(setup)

        else:
            raise ValueError("Unexpected option: " + argv[i])
    return setup
327264
public function loadCommandLine(array $argv)
  {
    for ($i=0; $i<sizeof($argv); $i++) {
      $arg = $argv[$i];
      
      if (substr($arg, 0, 2) == "--") {
        $arg = substr($arg, 2);
        
        $parts = explode("=", $arg);
        $name = array_shift($parts);
        $value = implode("=", $parts);
        
        $this->{$name} = $value;
      }
    }
  }
346442
public  static <T> T at(int i, T[] args)
	{
		if(args == null || i < 0)
			return null;
		
		if(i>= args.length)
			return null;
		
		return args[i];
	}
687386
protected function runShell(Shell $shell, array $argv)
    {
        try {
            $shell->initialize();

            return $shell->runCommand($argv, true);
        } catch (StopException $e) {
            return $e->getCode();
        }
    }
1250075
public static function main(array $argv = [], $command = null)
    {
        $code = 0;

        $output = new ConsoleOutput();
        $input  = new ArgvInput();

        try {
            $c = static::createCli();

            array_shift($argv);

            if (null !== $command) {
                array_unshift($argv, $command);
            }

            $c->run($input, $output, $argv);
        } catch (\Exception $e) {
            if ('true' !== getenv('DEV_QUIET')) {
                $output->writeln(sprintf('<error>Error #%d: %s</error>', $e->getCode(), $e->getMessage()));
            }

            $code = ($e->getCode() > 0 && $e->getCode() < 255) ? $e->getCode() : 255;
        }

        return $code;
    }
1174977
public function commandFor(array $argv): Command
    {
        $argv += [null, null, null];

        return
             // cmd
            $this->commands[$argv[1]]
            // cmd alias
            ?? $this->commands[$this->aliases[$argv[1]] ?? null]
            // default.
            ?? $this->commands[$this->default];
    }