protected void execCli(Cli<Callable<?>> parser, String ...args) { try { log.debug("Parsing command line arguments: {}", Arrays.asList(args)); Callable<?> command = parser.parse(args); log.debug("Executing command: {}", command); command.call(); System.exit(SUCCESS); } catch (ParseException pe) { // looks like the user typed it wrong System.err.println("Parse error: " + pe.getMessage()); // display // error System.err.println(getUsageInfo(parser)); // display cli help System.exit(PARSE_ERROR); } catch (FatalConfigurationRuntimeException e) { log.error("Configuration error: "+e.getMessage(), e.getCause()); System.err.println("Configuration error: " + e.getMessage()); System.exit(CONFIGURATION_ERROR); } catch (FatalRuntimeException e) { // anticipated non-configuration error log.error("Startup error: "+e.getMessage(), e.getCause()); System.err.println("Startup error: "+e.getMessage()); System.exit(EXECUTION_ERROR); } catch (Exception e) { // unexpected error during command execution log.error("Execution error: " + e.getMessage(), e); System.err.println("Execution error: " + e.getMessage()); if (!(e instanceof UserFacingException)) e.printStackTrace(); System.exit(EXECUTION_ERROR); } }
protected void execCli(Cli<BrooklynCommand> parser, String ...args) { try { log.debug("Parsing command line arguments: {}", Arrays.asList(args)); BrooklynCommand command = parser.parse(args); log.debug("Executing command: {}", command); command.call(); System.exit(SUCCESS); } catch (ParseException pe) { // looks like the user typed it wrong System.err.println("Parse error: " + pe.getMessage()); // display // error System.err.println(getUsageInfo(parser)); // display cli help System.exit(PARSE_ERROR); } catch (FatalConfigurationRuntimeException e) { log.error("Configuration error: "+e.getMessage(), e.getCause()); System.err.println("Configuration error: " + e.getMessage()); System.exit(CONFIGURATION_ERROR); } catch (FatalRuntimeException e) { // anticipated non-configuration error log.error("Startup error: "+e.getMessage(), e.getCause()); System.err.println("Startup error: "+e.getMessage()); System.exit(EXECUTION_ERROR); } catch (Exception e) { // unexpected error during command execution log.error("Execution error: " + e.getMessage(), e); System.err.println("Execution error: " + e.getMessage()); if (!(e instanceof UserFacingException)) e.printStackTrace(); System.exit(EXECUTION_ERROR); } }