}
private void invokeFunctionOrMethod(Shell shellState, ScriptEngine engine, CommandLine cl, Object[] args) {
try {
Invocable inv = (Invocable) engine;
if (cl.hasOption(function.getOpt())) {
inv.invokeFunction(cl.getOptionValue(function.getOpt()), args);
} else if (cl.hasOption(object.getOpt())) {
String objectMethod = cl.getOptionValue(object.getOpt());
String[] parts = objectMethod.split(":");
if (!(parts.length == 2)) {
shellState.printException(new Exception("Object and Method must be supplied"));
return;
}
String objectName = parts[0];
String methodName = parts[1];
Object obj = engine.get(objectName);
inv.invokeMethod(obj, methodName, args);
}
} catch (Exception e) {
shellState.printException(e);
}