private static CommandContext initCommandContext(String defaultHost, int defaultPort, String username, char[] password, boolean initConsole, boolean connect) throws CliInitializationException {
final CommandContext cmdCtx = CommandContextFactory.getInstance().newCommandContext(defaultHost, defaultPort, username, password, initConsole);
if(connect) {
try {
cmdCtx.connectController();
} catch (CommandLineException e) {
throw new CliInitializationException("Failed to connect to the controller", e);
}
}
return cmdCtx;