String actionString = cmdLineArgs[currentArg];
if (actionString.startsWith("-") || actionString.startsWith("--")) {
throw new IllegalArgumentException("Unknown option: " + actionString);
}
Action foundAction = lookupAction(actions, cmdLineArgs, currentArg);
if (foundAction == null) {
throw new IllegalArgumentException("Expected an action: " + buildActionString(actions));
}
currentArg += foundAction.getNames().length;
List<String> actionArgs = Arrays.asList(cmdLineArgs).subList(currentArg, cmdLineArgs.length);
foundAction.setArgs(actionArgs);
return new ParseResult(parsedOptions, foundAction);
}