Parses the arguments.

@param args Arguments
493528
public static JUnitCommandLineParseResult parse(String[] args) {
        JUnitCommandLineParseResult result = new JUnitCommandLineParseResult();

        result.parseArgs(args);

        return result;
    }
977644
protected String getArguments(Object[] args) {

        if (args == null || args.length == 0) {
            return "";
        }

        StringBuilder sb = new StringBuilder();

        if (args.length == 1) {
            Object arg = args[0];
            String param = getSingleArgParameterAsString(arg);
            String displayParam = getSingleArgDisplayParameter(param);
            if (arg instanceof String) {
                sb.append("\"");
                sb.append(displayParam);
                sb.append("\"");
            } else {
                sb.append(displayParam);
            }
        } else {
            for (int i = 0; i < args.length; i++) {
                Object arg = args[i];
                boolean lastArg = i == args.length - 1;
                String param = getParameterAsString(arg);
                String displayParam = getDisplayParameter(param);
                if (arg instanceof String) {
                    sb.append("\"");
                    sb.append(displayParam);
                    sb.append("\"");
                } else {
                    sb.append(displayParam);
                }

                if (!lastArg) {
                    sb.append(",");
                }
            }
        }

        return sb.toString();
    }
343383
private static void validateArguments(String[] args) {
    if (ArrayUtils.isEmpty(args)) {
      System.err.printf("$ java -server ... %s <port>%n", EchoServer.class.getName());
      System.exit(1);
    }
  }
1360738
public static Map<String, String> parseArgs(String[] args) {
        Map<String, String> argsMap = new HashMap<>();
        if (null == args || args.length == 0) {
            return argsMap;
        }
        for (String arg : args) {
            if (arg.startsWith("--") && arg.contains("=")) {
                String[] param = arg.substring(2).split("=");
                argsMap.put(param[0], param[1]);
            }
        }
        return argsMap;
    }
674911
public String[] parse(final String[] args) {
    parsed = new HashMap<String, String>(options.size());
    ArrayList<String> unparsed = null;
    for (int i = 0; i < args.length; i++) {
      final String arg = args[i];
      String[] opt = options.get(arg);
      if (opt != null) {  // Perfect match: got --foo
        if (opt[0] != null) {  // This option requires an argument.
          if (++i < args.length) {
            parsed.put(arg, args[i]);
          } else {
            throw new IllegalArgumentException("Missing argument for " + arg);
          }
        } else {
          parsed.put(arg, null);
        }
        continue;
      }
      // Is it a --foo=blah?
      final int equal = arg.indexOf('=', 1);
      if (equal > 0) {  // Looks like so.
        final String name = arg.substring(0, equal);
        opt = options.get(name);
        if (opt != null) {
          parsed.put(name, arg.substring(equal + 1, arg.length()));
          continue;
        }
      }
      // Not a flag.
      if (unparsed == null) {
        unparsed = new ArrayList<String>(args.length - i);
      }
      if (!arg.isEmpty() && arg.charAt(0) == '-') {
        if (arg.length() == 2 && arg.charAt(1) == '-') {  // `--'
          for (i++; i < args.length; i++) {
            unparsed.add(args[i]);
          }
          break;
        }
        throw new IllegalArgumentException("Unrecognized option " + arg);
      }
      unparsed.add(arg);
    }
    if (unparsed != null) {
      return unparsed.toArray(new String[unparsed.size()]);
    } else {
      return new String[0];
    }
  }
784158
public void command(String... args)
    {
        try
        {
            setArgs(args);
        }
        catch (CmdArgsException ex)
        {
            ex.printStackTrace();
            Logger logger = Logger.getLogger(CmdArgs.class.getName());
            logger.log(Level.SEVERE, Arrays.toString(args));
            logger.log(Level.SEVERE, ex.getMessage(), ex);
            logger.log(Level.SEVERE, ex.usage());
            System.exit(-1);
        }
    }
1051043
public static void main(String[] args) throws ParseException {
		CliFrontend cli = new CliFrontend();
		int retCode = cli.parseParameters(args);
		System.exit(retCode);
	}
45694
void parseArgs(String[] args) {
    int i = 0;
    while (true) {
      if (i >= args.length) {
        break;
      }

      String s = args[i];
      if (s.equals("-h") ||
              s.equals("help") ||
              s.equals("-help") ||
              s.equals("--help")) {
        usage();
      }
      else if (s.equals("-n") ||
              s.equals("-nodes")) {
        i++; if (i >= args.length) { usage(); }
        numNodes = Integer.parseInt(args[i]);
      }
      else if (s.equals("-o") ||
              s.equals("-output")) {
        i++; if (i >= args.length) { usage(); }
        outputPath = args[i];
      }
      else if (s.equals("-jobname")) {
        i++; if (i >= args.length) { usage(); }
        jobtrackerName = args[i];
      }
      else if (s.equals("-mapperXmx")) {
        i++; if (i >= args.length) { usage(); }
        mapperXmx = args[i];
      }
      else if (s.equals("-extramempercent")) {
        i++; if (i >= args.length) { usage(); }
        extraMemPercent = Integer.parseInt(args[i]);
      }
      else if (s.equals("-driverif")) {
        i++; if (i >= args.length) { usage(); }
        driverCallbackIp = args[i];
      }
      else if (s.equals("-driverport")) {
        i++; if (i >= args.length) { usage(); }
        driverCallbackPort = Integer.parseInt(args[i]);
      }
      else if (s.equals("-network")) {
        i++; if (i >= args.length) { usage(); }
        network = args[i];
      }
      else if (s.equals("-timeout")) {
        i++; if (i >= args.length) { usage(); }
        cloudFormationTimeoutSeconds = Integer.parseInt(args[i]);
      }
      else if (s.equals("-disown")) {
        disown = true;
      }
      else if (s.equals("-notify")) {
        i++; if (i >= args.length) { usage(); }
        clusterReadyFileName = args[i];
      }
      else if (s.equals("-nthreads")) {
        i++; if (i >= args.length) { usage(); }
        nthreads = Integer.parseInt(args[i]);
      }
      else if (s.equals("-many_cols")) {
        manyCols = true;
      }
      else if (s.equals("-chunk_bytes")) {
        i++; if (i >= args.length) { usage(); }
        chunk_bytes = Integer.parseInt(args[i]);
      }
      else if (s.equals("-data_max_factor_levels")) {
        i++; if (i >= args.length) { usage(); }
        data_max_factor_levels = Integer.parseInt(args[i]);
      }
      else if (s.equals("-baseport")) {
        i++; if (i >= args.length) { usage(); }
        basePort = Integer.parseInt(args[i]);
        if ((basePort < 0) || (basePort > 65535)) {
            error("Base port must be between 1 and 65535");
        }
      }
      else if (s.equals("-beta")) {
        beta = true;
      }
      else if (s.equals("-random_udp_drop")) {
        enableRandomUdpDrop = true;
      }
      else if (s.equals("-ea")) {
        enableExceptions = true;
      }
      else if (s.equals("-verbose:gc")) {
        enableVerboseGC = true;
      }
      else if (s.equals("-verbose:class")) {
        enableVerboseClass = true;
      }
      else if (s.equals("-XX:+PrintCompilation")) {
        enablePrintCompilation = true;
      }
      else if (s.equals("-exclude")) {
        enableExcludeMethods = true;
      }
      else if (s.equals("-Dlog4j.defaultInitOverride=true")) {
        enableLog4jDefaultInitOverride = true;
      }
      else if (s.equals("-debug")) {
        enableDebug = true;
      }
      else if (s.equals("-suspend")) {
        enableSuspend = true;
      }
      else if (s.equals("-debugport")) {
        i++; if (i >= args.length) { usage(); }
        debugPort = Integer.parseInt(args[i]);
        if ((debugPort < 0) || (debugPort > 65535)) {
          error("Debug port must be between 1 and 65535");
        }
      }
      else if (s.equals("-XX:+PrintGCDetails")) {
        enablePrintGCDetails = true;
      }
      else if (s.equals("-XX:+PrintGCTimeStamps")) {
        enablePrintGCTimeStamps = true;
      }
      else if (s.equals("-gc")) {
        enableVerboseGC = true;
        enablePrintGCDetails = true;
        enablePrintGCTimeStamps = true;
      }
      else if (s.equals("-license")) {
        i++; if (i >= args.length) { usage(); }
        licenseFileName = args[i];
      }
      else if (s.equals("-extraJavaOpts")) {
        i++; if (i >= args.length) { usage(); }
        extraJavaOpts = args[i];
      }
      else {
        error("Unrecognized option " + s);
      }

      i++;
    }

    // Check for mandatory arguments.
    if (numNodes < 1) {
      error("Number of H2O nodes must be greater than 0 (must specify -n)");
    }
    if (outputPath == null) {
      error("Missing required option -output");
    }
    if (mapperXmx == null) {
      error("Missing required option -mapperXmx");
    }

    // Check for sane arguments.
    if (! mapperXmx.matches("[1-9][0-9]*[mgMG]")) {
      error("-mapperXmx invalid (try something like -mapperXmx 4g)");
    }

    if (extraMemPercent < 0) {
      extraMemPercent = DEFAULT_EXTRA_MEM_PERCENT;
    }

    if (jobtrackerName == null) {
      Random rng = new Random();
      int num = rng.nextInt(99999);
      jobtrackerName = "H2O_" + num;
    }

    if (network == null) {
      network = "";
    }
    else {
      String[] networks;
      if (network.contains(",")) {
        networks = network.split(",");
      }
      else {
        networks = new String[1];
        networks[0] = network;
      }

      for (int j = 0; j < networks.length; j++) {
        String n = networks[j];
        Pattern p = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)/(\\d+)");
        Matcher m = p.matcher(n);
        boolean b = m.matches();
        if (! b) {
          error("network invalid: " + n);
        }

        for (int k = 1; k <=4; k++) {
          int o = Integer.parseInt(m.group(k));
          if ((o < 0) || (o > 255)) {
            error("network invalid: " + n);
          }

          int bits = Integer.parseInt(m.group(5));
          if ((bits < 0) || (bits > 32)) {
            error("network invalid: " + n);
          }
        }
      }
    }

    if (network == null) {
      error("Internal error, network should not be null at this point");
    }

    if ((nthreads >= 0) && (nthreads < 4)) {
      error("nthreads invalid (must be >= 4): " + nthreads);
    }

    if (licenseFileName != null) {
      try {
        licenseData = readFile(licenseFileName);
      }
      catch (Exception xe) {
        StringBuilder sb = new StringBuilder();
        sb.append("Failed to read license file: ");
        if (xe.getLocalizedMessage() != null) {
          sb.append(xe.getLocalizedMessage());
        }
        else {
          sb.append(licenseFileName);
        }

        error(sb.toString());
      }
    }
  }
607166
public void setArgs(String[] args) {
        if (args == null) {
            args = new String[]{};
        }
        this.args = args;
        this.argsList = Collections.unmodifiableList(new ArrayList<String>(Arrays.asList(args)));
    }
1184315
@Override
    public T parse(String arg) throws ParseException {
        if (isNull(arg)) {
            if (nullable) {
                return null;
            } else {
                throw new ParseException(ParseError.INVALID_PARAM, "Parameter doesn't take 'null' values: " + getName());
            }
        }
        return parseNonNull(arg);
    }
1312951
public static void logCommandLineArguments( String[] args ) {
		if( args == null || args.length < 1 ) return;
		for( int i=0; i < args.length; i++ ) {
			logMessage("Cmd line arg["+i+"]="+args[i]);
		}
	}
132716
@Override
    public boolean parseArguments(final PrintStream messageStream, final String[] args) {
        this.argv = args;
        this.messageStream = messageStream;
        if (prefix.isEmpty()) {
            commandLine = callerOptions.getClass().getSimpleName();
        }
        for (int i = 0; i < args.length; ++i) {
            final String arg = args[i];
            if (arg.equals("-h") || arg.equals("--help")) {
                messageStream.append(usage(false, true));
                return false;
            }
            if (arg.equals("-H") || arg.equals("--stdhelp")) {
                messageStream.append(usage(true, true));
                return false;
            }

            if (arg.equals("--version")) {
                messageStream.println(getVersion());
                return false;
            }

            final String[] pair = arg.split("=", 2);
            if (pair.length == 2) {
                if (pair[1].isEmpty() && i < args.length - 1) {
                    pair[1] = args[++i];
                }
                if (!parseOption(pair[0], pair[1], false)) {
                    messageStream.println();
                    messageStream.append(usage(true, true));
                    return false;
                }
            } else if (!parsePositionalArgument(arg)) {
                messageStream.println();
                messageStream.append(usage(false, true));
                return false;
            }
        }
        if (!checkNumArguments()) {
            messageStream.println();
            messageStream.append(usage(false, true));
            return false;
        }

        return true;
    }
1087913
private void parse(String[] s) {
    commandLineArgs = new Entry[0];
    for( int i = 0; i < s.length; ) {
      String next = (i+1<s.length)? s[i+1]: null;
      i += addArgument(s[i],next);
    }
  }
1088336
public void setArgs(String args) {
    for (String s : args.trim().split("\\s*,\\s*"))
      argv.add(s);
  }
708395
public void processArguments(String[] args) throws IOException {
        List<File> classFiles = new ArrayList<File>();
        List<File> jarFiles = new ArrayList<File>();
        String[] fileArgs = null;

        for (int i = 0; i < args.length; i++) {
            if (args[i].equalsIgnoreCase("--config")) {
                configFileParser = new TraceConfigFileParser(new File(args[++i]));
                configFileParser.parse();
                InstrumentationOptions options = configFileParser.getInstrumentationOptions();
                if (options.getAddFFDC()) {
                    setInstrumentWithFFDC(true);
                }
                setTraceType(options.getTraceType());
                setInstrumentationOptions(options);
            } else if (args[i].equalsIgnoreCase("--debug") || args[i].equals("-d")) {
                setDebug(true);
            } else if (args[i].equalsIgnoreCase("--tr")) {
                setTraceType(TraceType.TR);
            } else if (args[i].equalsIgnoreCase("--websphere")) {
                setTraceType(TraceType.TR);
            } else if (args[i].equalsIgnoreCase("--java-logging")) {
                setTraceType(TraceType.JAVA_LOGGING);
            } else if (args[i].equalsIgnoreCase("--jsr47")) {
                setTraceType(TraceType.JAVA_LOGGING);
            } else if (args[i].equalsIgnoreCase("--none")) {
                setTraceType(TraceType.NONE);
            } else if (args[i].equalsIgnoreCase("--no-trace")) {
                setTraceType(TraceType.NONE);
            } else if (args[i].equalsIgnoreCase("--ffdc")) {
                setInstrumentWithFFDC(true);
            } else if (args[i].equalsIgnoreCase("--compute-frames")) {
                setComputeFrames(true);
            } else {
                fileArgs = new String[args.length - i];
                System.arraycopy(args, i, fileArgs, 0, fileArgs.length);
                break;
            }
        }

        if (fileArgs == null || fileArgs.length == 0) {
            throw new IllegalArgumentException("Empty file lists are illegal");
        }

        for (int i = 0; i < fileArgs.length; i++) {
            File f = new File(fileArgs[i]);
            if (!f.exists()) {
                throw new IllegalArgumentException(f + " does not exist");
            } else if (f.isDirectory()) {
                classFiles.addAll(getClassFiles(f, null));
            } else if (f.getName().endsWith(".class")) {
                classFiles.add(f);
            } else if (f.getName().endsWith(".jar")) {
                jarFiles.add(f);
            } else if (f.getName().endsWith(".zip")) {
                jarFiles.add(f);
            } else {
                System.err.println(f + " is an unexpected file type; ignoring");
            }
        }

        setClassFiles(classFiles);
        setJarFiles(jarFiles);
    }
247746
static void parseArguments(String[] args) {
    for (AbstractH2OExtension e : extManager.getCoreExtensions()) {
      args = e.parseArguments(args);
    }
    parseH2OArgumentsTo(args, ARGS);
  }
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;
  }