public void main(
InvocationContext<Object> context,
@Argument(completer = ReplCompleter.class)
@Usage("the optional repl name")
String name) throws Exception {
ShellSession session = (ShellSession)context.getSession();
Repl current = session.getRepl();
if (name != null) {
if (name.equals(current.getLanguage().getName())) {
context.provide("Using repl " + name);
} else {
Repl found = null;
for (Language lang : session.getContext().getPlugins(Language.class)) {
if (lang.getName().equals(name)) {
if (lang.isActive()) {
found = lang.getRepl();
if (found != null) {
break;
} else {
throw new ScriptException("Language " + name + " does not provide a repl");
}
} else {
throw new ScriptException("Language " + name + " not active");
}
}
}
if (found != null) {
session.setRepl(found);
context.provide("Using repl " + name);
} else {
throw new ScriptException("Repl " + name + " not found");
}
}
} else {
//
LinkedHashMap<Repl, Boolean> repls = new LinkedHashMap<Repl, Boolean>();
repls.put(ScriptRepl.getInstance(), true);
for (Language lang : session.getContext().getPlugins(Language.class)) {
Repl repl = lang.getRepl();
if (repl != null) {
repls.put(repl, lang.isActive());
}
}