use of me.retrodaredevil.couchdbjava.response.ErrorResponse in project solarthing by wildmountainfarms.
the class SolarMain method doMain.
private static int doMain(String[] args) {
String logMessage = "Beginning main. Jar: " + getJarInfo();
LOGGER.info(SolarThingConstants.SUMMARY_MARKER, "[LOG] " + logMessage);
System.out.println("[stdout] " + logMessage);
System.err.println("[stderr] " + logMessage);
Cli<CommandOptions> cli = CliFactory.createCli(CommandOptions.class);
final CommandOptions commandOptions;
try {
commandOptions = cli.parseArguments(args);
} catch (ArgumentValidationException ex) {
System.out.println(cli.getHelpMessage());
if (ex instanceof HelpRequestedException) {
return 0;
}
LOGGER.error(SolarThingConstants.SUMMARY_MARKER, ex.getMessage());
LOGGER.error(SolarThingConstants.SUMMARY_MARKER, "(Fatal)Incorrect args");
return SolarThingConstants.EXIT_CODE_INVALID_OPTIONS;
}
if (commandOptions.getBaseConfigFile() != null) {
return doMainCommand(commandOptions, commandOptions.getBaseConfigFile());
}
if (commandOptions.getCouchDbSetupFile() != null) {
final DatabaseConfig config;
try {
config = ConfigUtil.MAPPER.readValue(commandOptions.getCouchDbSetupFile(), DatabaseConfig.class);
} catch (IOException e) {
e.printStackTrace();
System.err.println("Problem reading CouchDB database settings file.");
return SolarThingConstants.EXIT_CODE_INVALID_CONFIG;
}
DatabaseSettings settings = config.getSettings();
if (!(settings instanceof CouchDbDatabaseSettings)) {
System.err.println("Must be CouchDB database settings!");
return SolarThingConstants.EXIT_CODE_INVALID_CONFIG;
}
try {
return CouchDbSetupMain.createFrom((CouchDbDatabaseSettings) settings).doCouchDbSetupMain();
} catch (CouchDbException e) {
if (e instanceof CouchDbCodeException) {
ErrorResponse error = ((CouchDbCodeException) e).getErrorResponse();
if (error != null) {
System.err.println(error.getError());
System.err.println(error.getReason());
}
}
throw new RuntimeException(e);
}
}
List<String> legacyArguments = commandOptions.getLegacyOptionsRaw();
if (legacyArguments == null || legacyArguments.isEmpty()) {
System.err.println(cli.getHelpMessage());
return SolarThingConstants.EXIT_CODE_INVALID_OPTIONS;
}
System.err.println("Invalid sub command: " + legacyArguments.get(0));
return SolarThingConstants.EXIT_CODE_INVALID_OPTIONS;
}
Aggregations