name = ((String) param).substring(0, ((String) param).indexOf('='));
value = ((String) param).substring(((String) param).indexOf('=') + 1);
} else {
name = (String) param;
}
Option option = null;
for (Option opt : options.keySet()) {
if (name.equals(opt.name()) || Arrays.asList(opt.aliases()).contains(name)) {
option = opt;
break;
}
}
if (option == null) {
throw new CommandException(commandErrorSt +
Ansi.ansi()
.a("undefined option ")
.a(Ansi.Attribute.INTENSITY_BOLD)
.a(param)
.a(Ansi.Attribute.INTENSITY_BOLD_OFF)
.newline()
.a("Try <command> --help' for more information.")
.toString(),
"Undefined option: " + param);
}
Field field = options.get(option);
if (value == null && (field.getType() == boolean.class || field.getType() == Boolean.class)) {
value = Boolean.TRUE;
}
if (value == null && it.hasNext()) {
value = it.next();
}
if (value == null) {
throw new CommandException(commandErrorSt +
Ansi.ansi().a("missing value for option ").bold().a(param).boldOff().toString(),
"Missing value for option: " + param
);
}
if (option.multiValued()) {
@SuppressWarnings("unchecked")
List<Object> l = (List<Object>) optionValues.get(option);
if (l == null) {
l = new ArrayList<Object>();
optionValues.put(option, l);
}
l.add(value);
} else {
optionValues.put(option, value);
}
} else {
processOptions = false;
if (argIndex >= orderedArguments.size()) {
throw new CommandException(commandErrorSt +
Ansi.ansi().a("too many arguments specified").toString(),
"Too many arguments specified"
);
}
Argument argument = orderedArguments.get(argIndex);
if (!argument.multiValued()) {
argIndex++;
}
if (argument.multiValued()) {
@SuppressWarnings("unchecked")
List<Object> l = (List<Object>) argumentValues.get(argument);
if (l == null) {
l = new ArrayList<Object>();
argumentValues.put(argument, l);
}
l.add(param);
} else {
argumentValues.put(argument, param);
}
}
}
// Check required arguments / options
for (Option option : options.keySet()) {
if (option.required() && optionValues.get(option) == null) {
throw new CommandException(commandErrorSt +
Ansi.ansi().a("option ").bold().a(option.name()).boldOff().a(" is required").toString(),
"Option " + option.name() + " is required"
);
}
}
for (Argument argument : orderedArguments) {
if (argument.required() && argumentValues.get(argument) == null) {