Map<String, IValue> params = new HashMap<String,IValue>();
for (int i = 0; i < commandline.length; i++) {
if (commandline[i].equals("-help")) {
throw new CommandlineError("Help", func);
}
else if (commandline[i].startsWith("-")) {
String label = commandline[i].replaceFirst("^-+", "");
Type expected = expectedTypes.get(label);
if (expected == null) {
throw new CommandlineError("unknown argument: " + label, func);
}
if (expected.isSubtypeOf(tf.boolType())) {
if (i == commandline.length - 1 || commandline[i+1].startsWith("-")) {
params.put(label, vf.bool(true));
}
else if (i < commandline.length - 1) {
String arg = commandline[++i].trim();
if (arg.equals("1") || arg.equals("true")) {
params.put(label, vf.bool(true));
}
else {
params.put(label, vf.bool(false));
}
}
continue;
}
else if (i == commandline.length - 1 || commandline[i+1].startsWith("-")) {
throw new CommandlineError("expected option for " + label, func);
}
else if (expected.isSubtypeOf(tf.listType(tf.valueType()))) {
IListWriter writer = vf.listWriter();
while (i + 1 < commandline.length && !commandline[i+1].startsWith("-")) {