Groovysh shell = new Groovysh();
// Install our error hook (exception handling)
shell.setErrorHook(new MethodClosure(ThrowableDisplayer.class, "errorHook"));
CommandRegistry registry = shell.getRegistry();
@SuppressWarnings("unchecked")
Iterator<Command> iterator = registry.iterator();
while (iterator.hasNext()) {
Command command = iterator.next();
if (!commandsToKeep.contains(command.getName())) {
iterator.remove();
// remove from "names" set to avoid duplicate error.
registry.remove(command);
}
}
shell.register(new HelpCommand(shell));
shell.register(new SetCommand(shell));