try {
ModuleEnvironment modEnv = getHeap().getModule(module);
setCurrentEnvt(modEnv);
Name name = Names.toName(function, modEnv.getLocation());
OverloadedFunction func = (OverloadedFunction) getCurrentEnvt().getVariable(name);
if (func == null) {
throw new UndeclaredVariable(function, name);
}
AbstractFunction main = func.getFunctions().get(0);
if (func.getFunctions().size() > 1) {
throw new CommandlineError("should only have one main function", main);
}
if (main.getArity() == 1) {
return func.call(getMonitor(), new Type[] { tf.listType(tf.stringType()) },new IValue[] { parsePlainCommandLineArgs(commandline)}, null).getValue();
}
else if (main.hasKeywordArgs() && main.getArity() == 0) {
Map<String, IValue> args = parseKeywordCommandLineArgs(monitor, commandline, main);
return func.call(getMonitor(), new Type[] { },new IValue[] {}, args).getValue();
}
else {
throw new CommandlineError("main function should either have one argument of type list[str], or keyword parameters", main);
}
}