// check if option is a valid one
CmdLineOption option = getOptionByName(arg.getName(),
validOptions);
if (option == null) {
throw new CmdLineConstructionException("Invalid option: '" + arg.getName() + "'");
}
// read found option
CmdLineOptionInstance specifiedOption = getOption(parsedArgs, option);
// Check if we are currently loading subOptions.
if (!groupOptions.isEmpty()) {
CmdLineOptionInstance currentGroup = groupOptions.peek();
// Check if option is NOT a subOption for current group.
if (!isSubOption(currentGroup.getOption(), option)) {
// Check if current group was expecting more subOptions.
Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
if (!requiredSubOptions.isEmpty()) {
throw new CmdLineConstructionException(
"Missing the following required subOptions for '"
+ currentGroup.getOption()
+ "': "
+ sortOptionsByRequiredStatus(requiredSubOptions));
} else if (currentGroup.getSubOptions().isEmpty()) {
throw new CmdLineConstructionException(
"Must specify a subOption for group option '"
+ currentGroup.getOption() + "'");
} else {
// pop group and add to list of specified options.
optionInstances.add(groupOptions.pop());
}
// It is a sub-option...
} else {
// Add option to current group subOptions.
currentGroup.addSubOption(specifiedOption);
continue;
}
}
if (option instanceof GroupCmdLineOption) {
// Push group as current group.
groupOptions.push(specifiedOption);
if (!parsedArgs.hasNext()) {
throw new CmdLineConstructionException(
"Must specify a subOption for group option '"
+ specifiedOption.getOption() + "'");
}
} else if (option.isSubOption()) {
throw new CmdLineConstructionException("Option '" + option
+ "' is a subOption, but was used at top level Option");
} else {
// Option good to go.
optionInstances.add(specifiedOption);
}
} else {
throw new CmdLineConstructionException("Invalid argument: '" + arg + "'");
}
}
while (!groupOptions.isEmpty()) {
CmdLineOptionInstance currentGroup = groupOptions.pop();
Set<CmdLineOption> requiredSubOptions = verifyGroupHasRequiredSubOptions(currentGroup);
if (!requiredSubOptions.isEmpty()) {
throw new CmdLineConstructionException(
"Missing the following required subOptions for '"
+ currentGroup.getOption() + "': "
+ sortOptionsByRequiredStatus(requiredSubOptions));
} else {