parseArgs Command Line Interface (CLI) utility function.
@author   Patrick Fisher <patrick@pwfisher.com>
@see      https://github.com/pwfisher/CommandLine.php
513734
protected function parseArgs( $argv = null ) {
		$argv = $argv ? $argv : $_SERVER['argv']; array_shift($argv); $o = [];
		for ($i = 0, $j = count($argv); $i < $j; $i++) { $a = $argv[$i];
			if (substr($a, 0, 2) == '--') { $eq = strpos($a, '=');
				if ($eq !== false) { $o[substr($a, 2, $eq - 2)] = substr($a, $eq + 1); }
				else { $k = substr($a, 2);
					if ($i + 1 < $j && $argv[$i + 1][0] !== '-') { $o[$k] = $argv[$i + 1]; $i++; }
					else if (!isset($o[$k])) { $o[$k] = true; } } }
			else if (substr($a, 0, 1) == '-') {
				if (substr($a, 2, 1) == '=') { $o[substr($a, 1, 1)] = substr($a, 3); }
				else {
					foreach (str_split(substr($a, 1)) as $k) { if (!isset($o[$k])) { $o[$k] = true; } }
					if ($i + 1 < $j && $argv[$i + 1][0] !== '-') { $o[$k] = $argv[$i + 1]; $i++; } } }
			else { $o[] = $a; } }
		return $o;
	}
115527
private static CommandLine parseArgs(String[] args) throws ParseException {
    Options options = new Options();

    // Input
    Option o = new Option("i", "input", true,
        "input directory as hdfs path, or local as file://");
    o.setArgName("input-path");
    o.setRequired(true);
    options.addOption(o);

    // Input
    o = new Option("o", "output", true, "output directory");
    o.setArgName("input-path");
    o.setRequired(true);
    options.addOption(o);

    // Whether to skip existing files or not.
    o = new Option("s", "skipExisting", false,
        "skip existing files. Cannot be used together with m for move.");
    o.setRequired(false);
    options.addOption(o);

    // Maximum number of files to retain in the specified input directory.
    o = new Option(
        "x",
        "maXretention",
        true,
        "The maximum number of the most recent files to retain in the input directory after processing."
            + " Can be used by HDFS input paths only. Mutually exclusive with s (move),"
            + " but can be used in combination with s (skipExisting)");
    o.setRequired(false);
    options.addOption(o);

    // Whether files need to be moved
    o = new Option("m", "move", false, "move all files rather than copying."
        + "Delete source if target already exists."
        + " Can be used with HDFS input paths only. "
        + " Mutually exlusive with s (skipExisting)");
    o.setRequired(false);
    options.addOption(o);

    // Debugging
    options.addOption("d", "debug", false, "switch on DEBUG log level");
    o.setRequired(false);
    options.addOption(o);

    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;
    try {
      commandLine = parser.parse(options, args);
    } catch (Exception e) {
      System.err.println("ERROR: " + e.getMessage() + "\n");
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp(NAME + " ", options, true);
      System.exit(-1);
    }

    return commandLine;
  }
1358406
public void cli(String[] args) {
        CommandLineParser cli = new CommandLineParser();
        cli.addOption(NamedOption.builder()
                .name("data")
                .description("Data to use for training or testing")
                .required(true)
                .type(Resource.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("format")
                .description("Format for reading data")
                .defaultValue("JSON_OPL")
                .type(String.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("corpusType")
                .description("Type of corpus to create (e.g. in-memory)")
                .defaultValue("IN_MEMORY")
                .type(CorpusType.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("mode")
                .description("Train/Test/Split")
                .defaultValue("TEST")
                .type(Mode.class)
                .build());
        cli.addOption(NamedOption.builder()
                .name("model")
                .description("Model to save/load")
                .type(Resource.class)
                .required(true)
                .build());
        cli.addOption(NamedOption.builder()
                .name("undersample")
                .description("Undersample")
                .type(Boolean.class)
                .required(false)
                .defaultValue(false)
                .build());
        cli.addOption(NamedOption.builder()
                .name("oversample")
                .description("Oversample")
                .type(Boolean.class)
                .required(false)
                .defaultValue(false)
                .build());
        cli.parse(args);
        Hermes.initializeApplication(args);

        Dataset<Instance> data = getDataset(cli.get("data"), cli.get("format"), cli.get("corpusType"),
                cli.get("undersample"),
                cli.get("oversample"));

        Mode mode = cli.get("mode");
        switch (mode) {
            case TEST:
                try {
                    this.classifier = Cast.<BasicTextClassifier>as(TextClassifier.read(cli.get("model"))).classifier;
                } catch (Exception e) {
                    throw Throwables.propagate(e);
                }
                test(data);
                break;
            case SPLIT:
                TrainTestSplit<Instance> split = Iterables.getFirst(data.split(0.8), null);
                train(split.getTrain());
                test(split.getTest());
                break;
            case TRAIN:
                train(data);
                try {
                    write(cli.get("model"));
                } catch (Exception e) {
                    throw Throwables.propagate(e);
                }
                break;
            case CV3:
            case CV10:
                TrainTestSet<Instance> folds = data.fold(mode == Mode.CV3 ? 3 : 10);
                ClassifierEvaluation evaluation = new ClassifierEvaluation();
                for (TrainTestSplit<Instance> fold : folds) {
                    train(fold.getTrain());
                    evaluation.merge(test(fold.getTest(), false));
                }
                evaluation.output(System.out);
                break;
            default:
                System.err.println("Unknown option");
        }
    }
169435
CommandLine parse(DefaultCommandLine cl, String[] args) {
        parseInternal(cl, args, true);
        return cl;
    }
155357
public final void parseCLI(final String[] args) throws IOException,
      JDOMException {
    try {
      this.parsedArguments = this.argParser.parseArgs(args);
      System.err.println("CLI options: " + this.parsedArguments);
      if (args[0].equals("parse")) {
        annotate(System.in, System.out);
      } else if (args[0].equals("eval")) {
        eval();
      } else if (args[0].equals("train")) {
        train();
      } else if (args[0].equals("server")) {
        server();
      } else if (args[0].equals("client")) {
        client(System.in, System.out);
      }
    } catch (final ArgumentParserException e) {
      this.argParser.handleError(e);
      System.out.println("Run java -jar target/ixa-pipe-parse-" + this.version
          + ".jar" + " (parse|train|eval|server|client) -help for details");
      System.exit(1);
    }
  }
914549
private function cmdHelp($args)
    {
        $help = isset($args[1]) ? $args[1] : 'help';
        $file = __DIR__.'/../help/'.$help.'.txt';

        if (!file_exists($file)) {
            return $this->error('&help-not-found');
        }

        echo file_get_contents(__DIR__.'/../help/'.$help.'.txt');
    }
388315
private static boolean parseInputArgs(String[] args) {
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd;
    try {
      cmd = parser.parse(OPTIONS, args);
    } catch (ParseException e) {
      System.out.println("Failed to parse input args: " + e);
      return false;
    }
    sHelp = cmd.hasOption("help");
    sType = OperationType.valueOf(cmd.getOptionValue("type", "READ"));
    sFileSize = FormatUtils.parseSpaceSize(cmd.getOptionValue("fileSize", "1KB"));
    sIterations = Integer.parseInt(cmd.getOptionValue("iterations", "1"));
    sConcurrency = Integer.parseInt(cmd.getOptionValue("concurrency", "1"));

    return true;
  }
1320252
private function cliIO()
    {
        $services = [
            'Cli\Input'  => 'input',
            'Cli\Output' => 'output',
        ];

        foreach ($services as $className => $classOffset) {
            $this->services->load($className, $classOffset);
        }
    }
1102246
function parseArgs() {
    var args = Array.prototype.slice.call(arguments);

    var ret = {
        query: args[0],
        params: [],
        options: {},
        callback: undefined,
        endCallback: undefined
    };

    args.shift();

    // If specified, params must be an array
    if (args[0] instanceof Array) {
        ret.params = args[0];
        args.shift();
    }

    // If specified, options must be a non-Function object
    if (! (args[0] instanceof Function)) {
        ret.options = args[0];
        args.shift();
    }

    ret.callback = args[0];
    ret.endCallback = args[1];

    if (ret.query === undefined || ret.callback === undefined) {
        throw new Error('query and callback are required');
    }

    return ret;
}
1346734
protected function parseArgs($args)
    {
        if (!is_array($args)) {
            return $args;
        }

        $this->silent = in_array('--silent', $args);
        if ($this->silent) {
            $args = array_values(array_diff($args, ['--silent']));
        }

        return $args;
    }
271468
function ParseArguments(cmd, args) {
  assert(_.isObject(cmd), 'require an object argument for "cmd".');
  assert(_.isObject(args), 'require an object argument for "args".');
  const argSpec = cmd.argSpec || [];
  const cmdName = cmd.name;

  //
  // Build a map of all flag aliases.
  //
  const allAliases = _.fromPairs(_.map(_.flatten(_.map(argSpec, 'flags')), (flagAlias) => {
    return [flagAlias, true];
  }));

  //
  // Make sure all provided flags are specified in the argSpec.
  //
  _.forEach(args, (argVal, argKey) => {
    if (argKey === '_') return; // ignore positional arguments
    if (!(argKey in allAliases)) {
      const d = argKey.length === 1 ? '-' : '--';
      throw new Error(
        `Unknown command-line option "${col.bold(d + argKey)}" specified ` +
        `for command "${col.bold(cmdName)}".`);
    }
  });

  //
  // Handle boolean flags specified as string values on the command line.
  //
  args = _.mapValues(args, (flagVal) => {
    if (_.isString(flagVal)) {
      if (flagVal === 'true') {
        return true;
      }
      if (flagVal === 'false') {
        return false;
      }
    }
    return flagVal;
  });

  //
  // For each flag in the argSpec, see if any alias of the flag is
  // present in `args`. If it is, then assign that value to *all*
  // aliases of the flag. If it is not present, then assign the
  // default value. Throw on unspecified required flags.
  //
  const finalFlags = {};
  _.forEach(argSpec, (aspec, idx) => {
    // Find the first alias of this flag that is specified in args, if at all.
    const foundAlias = _.find(aspec.flags, (flagAlias) => {
      return flagAlias && (flagAlias in args);
    });
    let assignValue = foundAlias ? args[foundAlias] : (aspec.defVal || aspec.default);

    // If defVal is an object, then we need to execute a function to get the
    // default value.
    if (_.isObject(assignValue)) {
      assert(
        _.isFunction(assignValue.fn),
        `Argspec entry ${idx} has an invalid 'defVal'/'default' property.`);
      assignValue = assignValue.fn.call(argSpec);
    }

    if (!_.isUndefined(assignValue)) {
      // Assign value to all aliases of flag.
      _.forEach(aspec.flags, (flagAlias) => {
        finalFlags[flagAlias] = assignValue;
      });
    }
  });

  // Copy positional arguments to finalFlags.
  finalFlags._ = args._;

  return finalFlags;
}
884774
public final void parseCLI(final String[] args)
      throws IOException, JDOMException {
    try {
      parsedArguments = argParser.parseArgs(args);
      System.err.println("CLI options: " + parsedArguments);
      switch (args[0]) {
      case ANNOTATE_PARSER_NAME:
        annotate(System.in, System.out);
        break;
      case SERVER_PARSER_NAME:
        server();
        break;
      case CLIENT_PARSER_NAME:
        client(System.in, System.out);
        break;
      }
    } catch (ArgumentParserException e) {
      argParser.handleError(e);
      System.out.println("Run java -jar target/ixa-pipe-nerc-" + version
          + "-exec.jar (tag|server|client) -help for details");
      System.exit(1);
    }
  }
1325741
def parse_command_line(args: List[str] = None, final: bool = True) -> List[str]:
    
    return options.parse_command_line(args, final=final)
703933
protected function createParser()
    {
        $geshi = new GeSHi();
        $parser = new Console_CommandLine();
        $parser->description = 'CLI interface to GeSHi, the generic syntax highlighter';
        $parser->version     = '0.1.0';

        $parser->addOption('css', array(
            'long_name'   => '--css',
            'description' => 'Use CSS classes',
            'action'      => 'StoreTrue',
            'default'     => false,
        ));
        $langs = $geshi->get_supported_languages();
        sort($langs);
        $parser->addOption('format', array(
            'short_name'  => '-f',
            'long_name'   => '--format',
            'description' => 'Format of file to highlight (e.g. php).',
            'help_name'   => 'FORMAT',
            'action'      => 'StoreString',
            'default'     => false,
            'choices'     => $langs,
        ));

        $parser->addArgument('infile', array('help_name' => 'source file'));

        return $parser;
    }
1050661
public static function cli($args)
    {
        $cwd = getcwd();
        $cli = new self($cwd);

        return $cli->run(array_slice($args, 1));
    }
412121
protected function parseArgs()
    {
        parent::parseArgs();
        if (empty($this->args['usuario']) or empty($this->args['clave'])) {
            $this->error('Debe indicar --usuario y --clave del usuario que se autenticará en el SII');
        }
        if (empty($this->args['contribuyente'])) {
            $this->args['contribuyente'] = $this->args['usuario'];
        }
        if (empty($this->args['salida'])) {
            $this->args['salida'] = 'libredte_mipyme_respaldo_'.$this->args['contribuyente'];
        }
        if (!is_dir($this->args['salida'])) {
            mkdir($this->args['salida'], 0755, true);
            mkdir($this->args['salida'].'/emitidos', 0755, true);
            mkdir($this->args['salida'].'/recibidos', 0755, true);
            mkdir($this->args['salida'].'/iecv', 0755, true);
        }
    }
191231
private function _parseArgs(array $args)
	{
		$arg = '';
		if(count($args) > 0)
		{
			foreach($args as $number => $argument)
			{
				if($number === 0)
				{
					$arg .= $argument;
				}
				else
				{
					$arg .= ', ' . $argument;
				}
			}
		}

		return $arg;
	}