in gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java [180:267]
public int boot(final String[] args) throws Exception {
assert args != null;
System.setProperty("jline.terminal", AutoDetectedTerminal.class.getName());
// Default is to be quiet
setConsoleLogLevel("WARN");
CommandLineProcessor clp = new CommandLineProcessor(this);
clp.setStopAtNonOption(true);
clp.process(args);
// Setup a refereence for our exit code so our callback thread can tell if we've shutdown normally or not
final AtomicReference<Integer> codeRef = new AtomicReference<Integer>();
int code = ExitNotification.DEFAULT_CODE;
Runtime.getRuntime().addShutdownHook(new Thread("GShell Shutdown Hook") {
public void run() {
if (codeRef.get() == null) {
// Give the user a warning when the JVM shutdown abnormally, normal shutdown
// will set an exit code through the proper channels
if (!io.isSilent()) {
io.err.println();
io.err.println(messages.getMessage("warning.abnormalShutdown"));
}
}
io.flush();
}
});
try {
ShellBuilder builder = new ShellBuilderImpl();
builder.setClassLoader(getClass().getClassLoader());
builder.setIo(io);
if (!io.isQuiet() && !io.isSilent()) {
// Configure the download monitor
ArtifactResolver artifactResolver = builder.getContainer().getBean(ArtifactResolver.class);
artifactResolver.setTransferListener(new ProgressSpinnerMonitor(io));
}
// --help and --version need access to the application's information, so we have to handle these options late
if (help|version) {
ApplicationModel applicationModel = builder.getApplicationModel();
if (help) {
Printer printer = new Printer(clp);
printer.setMessageSource(messages);
printer.printUsage(io.out, applicationModel.getBranding().getProgramName());
}
else if (version) {
io.out.println(applicationModel.getVersion());
}
io.out.flush();
throw new ExitNotification();
}
// Build the shell instance
Shell gshell = builder.create();
// clp gives us a list, but we need an array
String[] _args = {};
if (commandArgs != null) {
_args = commandArgs.toArray(new String[commandArgs.size()]);
}
if (commands != null) {
gshell.execute(commands);
}
else if (interactive) {
gshell.run(_args);
}
else {
gshell.execute(_args);
}
}
catch (ExitNotification n) {
code = n.code;
}
codeRef.set(code);
return code;
}