public int parse(String argv[]) throws IOException { int arg = 0;  while (arg < argv.length) { String option = argv[arg]; if (!option.startsWith("-")) break;  String optionExtraPart = ""; int colon = option.indexOf(':'); if (colon >= 0) { optionExtraPart = option.substring(colon + 1); option = option.substring(0, colon); }  if (optionDescriptionMap.get(option) == null) throw new IllegalArgumentException("Unknown option: " + option);  if (requiresArgumentSet.contains(option)) { ++arg; if (arg >= argv.length) throw new IllegalArgumentException("Option " + option + " requires an argument"); String argument = argv[arg]; handleOptionWithArgument(option, argument); ++arg; } else { handleOption(option, optionExtraPart); ++arg; }
public int parse(String argv[], int minArgs, int maxArgs, String usage) { try { int count = parse(argv); int remaining = argv.length - count; if (remaining < minArgs || remaining > maxArgs) throw new RuntimeException("Wrong number of arguments"); return count; } catch (Exception e) { System.out.println(usage); System.out.println("Options:"); printUsage(System.out); System.exit(1); throw new RuntimeException(e);
	public int parse(String argv[]) throws IOException {		int arg = 0;		while (arg < argv.length) {			String option = argv[arg];			if (!option.startsWith("-"))				break;			String optionExtraPart = "";			int colon = option.indexOf(':');			if (colon >= 0) {				optionExtraPart = option.substring(colon + 1);				option = option.substring(0, colon);			}			if (optionDescriptionMap.get(option) == null)				throw new IllegalArgumentException("Unknown option: " + option);			if (requiresArgumentSet.contains(option)) {				++arg;				if (arg >= argv.length)					throw new IllegalArgumentException("Option " + option + " requires an argument");				String argument = argv[arg];				handleOptionWithArgument(option, argument);				++arg;			} else {				handleOption(option, optionExtraPart);				++arg;			}		}		return arg;	}