in gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ShellImpl.java [189:259]
public void run(final Object... args) throws Exception {
assert args != null;
ensureOpened();
log.debug("Starting interactive console; args: {}", args);
loadUserScript(application.getModel().getBranding().getInteractiveScriptName());
// Setup 2 final refs to allow our executor to pass stuff back to us
final AtomicReference<ExitNotification> exitNotifHolder = new AtomicReference<ExitNotification>();
final AtomicReference<Object> lastResultHolder = new AtomicReference<Object>();
// Whip up a tiny console executor that will execute shell command-lines
Console.Executor executor = new Console.Executor() {
public Result execute(final String line) throws Exception {
assert line != null;
try {
Object result = ShellImpl.this.execute(line);
lastResultHolder.set(result);
}
catch (ExitNotification n) {
exitNotifHolder.set(n);
return Result.STOP;
}
return Result.CONTINUE;
}
};
IO io = getContext().getIo();
// Setup the console runner
JLineConsole console = new JLineConsole(executor, io);
console.setPrompter(getPrompter());
console.setErrorHandler(getErrorHandler());
console.setHistory(getHistory());
// Attach completers if there are any
if (completers != null) {
// Have to use aggregate here to get the completion list to update properly
console.addCompleter(new AggregateCompleter(completers));
}
// Unless the user wants us to shut up, then display a nice welcome banner
if (!io.isQuiet()) {
String message = application.getModel().getBranding().getWelcomeMessage();
if (message != null) {
io.out.print(message);
io.out.println(repeat("-", io.getTerminal().getTerminalWidth() - 1));
io.out.flush();
}
}
// Check if there are args, and run them and then enter interactive
if (args.length != 0) {
execute(args);
}
// And then spin up the console and go for a jog
console.run();
// If any exit notification occured while running, then puke it up
ExitNotification n = exitNotifHolder.get();
if (n != null) {
throw n;
}
}