use of com.beust.jcommander.JCommander in project jphp by jphp-compiler.
the class CLI method main.
public static void main(String[] args) throws Throwable {
Arguments arguments = new Arguments();
JCommander commander = new JCommander(arguments, args);
CLI cli = new CLI(commander, arguments, System.out, args);
cli.process();
}
use of com.beust.jcommander.JCommander in project keywhiz by square.
the class CliMain method main.
public static void main(String[] args) throws Exception {
CliConfiguration config = new CliConfiguration();
JCommander commander = new JCommander();
Map<String, Object> commands = ImmutableMap.<String, Object>builder().put("login", new LoginActionConfig()).put("list", new ListActionConfig()).put("describe", new DescribeActionConfig()).put("add", new AddActionConfig()).put("update", new UpdateActionConfig()).put("delete", new DeleteActionConfig()).put("assign", new AssignActionConfig()).put("unassign", new UnassignActionConfig()).put("versions", new ListVersionsActionConfig()).put("rollback", new RollbackActionConfig()).build();
commander.setProgramName("KeyWhiz Configuration Utility");
commander.addObject(config);
for (Map.Entry<String, Object> entry : commands.entrySet()) {
commander.addCommand(entry.getKey(), entry.getValue());
}
try {
commander.parse(args);
} catch (ParameterException e) {
System.err.println("Invalid command: " + e.getMessage());
commander.usage();
System.exit(1);
}
String command = commander.getParsedCommand();
JCommander specificCommander = commander.getCommands().get(command);
Injector injector = Guice.createInjector(new CliModule(config, commander, specificCommander, command, commands));
CommandExecutor executor = injector.getInstance(CommandExecutor.class);
executor.executeCommand();
}
use of com.beust.jcommander.JCommander in project torodb by torodb.
the class Main method main.
public static void main(String[] args) throws Exception {
try {
Console console = JCommander.getConsole();
ResourceBundle cliBundle = PropertyResourceBundle.getBundle("CliMessages");
final CliConfig cliConfig = new CliConfig();
JCommander jCommander = new JCommander(cliConfig, cliBundle, args);
jCommander.setColumnSize(Integer.MAX_VALUE);
if (cliConfig.isVersion()) {
BuildProperties buildProperties = new DefaultBuildProperties();
console.println(buildProperties.getFullVersion());
System.exit(0);
}
if (cliConfig.isHelp()) {
jCommander.usage();
System.exit(0);
}
if (cliConfig.isHelpParam()) {
console.println(cliBundle.getString("cli.help-param-header"));
ConfigUtils.printParamDescriptionFromConfigSchema(Config.class, cliBundle, console, 0);
System.exit(0);
}
cliConfig.addParams();
final Config config = CliConfigUtils.readConfig(cliConfig);
if (cliConfig.isPrintConfig()) {
ConfigUtils.printYamlConfig(config, console);
System.exit(0);
}
if (cliConfig.isPrintXmlConfig()) {
ConfigUtils.printXmlConfig(config, console);
System.exit(0);
}
if (cliConfig.isPrintParam()) {
JsonNode jsonNode = ConfigUtils.getParam(config, cliConfig.getPrintParamPath());
if (jsonNode != null) {
console.print(jsonNode.asText());
}
System.exit(0);
}
configureLogger(cliConfig, config);
config.getBackend().getBackendImplementation().accept(new BackendImplementationVisitor() {
@Override
public void visit(AbstractDerby value) {
parseToropassFile(value);
}
@Override
public void visit(AbstractPostgres value) {
parseToropassFile(value);
}
public void parseToropassFile(BackendPasswordConfig value) {
try {
ConfigUtils.parseToropassFile(value);
} catch (Exception ex) {
throw new SystemException(ex);
}
}
});
AbstractReplication replication = config.getReplication();
if (replication.getAuth().getUser() != null) {
HostAndPort syncSource = HostAndPort.fromString(replication.getSyncSource()).withDefaultPort(27017);
ConfigUtils.parseMongopassFile(new MongoPasswordConfig() {
@Override
public void setPassword(String password) {
replication.getAuth().setPassword(password);
}
@Override
public String getUser() {
return replication.getAuth().getUser();
}
@Override
public Integer getPort() {
return syncSource.getPort();
}
@Override
public String getPassword() {
return replication.getAuth().getPassword();
}
@Override
public String getMongopassFile() {
return config.getReplication().getMongopassFile();
}
@Override
public String getHost() {
return syncSource.getHostText();
}
@Override
public String getDatabase() {
return replication.getAuth().getSource();
}
});
}
if (config.getBackend().isLike(AbstractPostgres.class)) {
AbstractPostgres postgres = config.getBackend().as(AbstractPostgres.class);
if (cliConfig.isAskForPassword()) {
console.print("Type database user " + postgres.getUser() + "'s password:");
postgres.setPassword(readPwd());
}
if (postgres.getPassword() == null) {
throw new SystemException("No password provided for database user " + postgres.getUser() + ".\n\n" + "Please add following line to file " + postgres.getToropassFile() + ":\n" + postgres.getHost() + ":" + postgres.getPort() + ":" + postgres.getDatabase() + ":" + postgres.getUser() + ":<password>\n" + "Replace <password> for database user " + postgres.getUser() + "'s password");
}
}
try {
Clock clock = Clock.systemDefaultZone();
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
@SuppressFBWarnings(value = "DM_EXIT", justification = "Since is really hard to stop cleanly all threads when an OOME is thrown we must " + "exit to avoid no more action is performed that could lead to an unespected " + "state")
public void uncaughtException(Thread t, Throwable e) {
if (e instanceof OutOfMemoryError) {
try {
LOGGER.error("Fatal out of memory: " + e.getLocalizedMessage(), e);
} finally {
System.exit(1);
}
}
}
});
Service stampedeService = StampedeBootstrap.createStampedeService(config, clock);
stampedeService.startAsync();
stampedeService.awaitTerminated();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
stampedeService.stopAsync();
stampedeService.awaitTerminated();
}));
} catch (CreationException ex) {
ex.getErrorMessages().stream().forEach(m -> {
if (m.getCause() != null) {
LOGGER.error(m.getCause().getMessage());
} else {
LOGGER.error(m.getMessage());
}
});
LogManager.shutdown();
System.exit(1);
}
} catch (Throwable ex) {
LOGGER.debug("Fatal error on initialization", ex);
Throwable rootCause = Throwables.getRootCause(ex);
String causeMessage = rootCause.getMessage();
LogManager.shutdown();
JCommander.getConsole().println("Fatal error while ToroDB was starting: " + causeMessage);
System.exit(1);
}
}
use of com.beust.jcommander.JCommander in project torodb by torodb.
the class Main method main.
public static void main(String[] args) throws Exception {
Console console = JCommander.getConsole();
ResourceBundle cliBundle = PropertyResourceBundle.getBundle("CliMessages");
final CliConfig cliConfig = new CliConfig();
JCommander jCommander = new JCommander(cliConfig, cliBundle, args);
jCommander.setColumnSize(Integer.MAX_VALUE);
if (cliConfig.isHelp()) {
jCommander.usage();
System.exit(0);
}
if (cliConfig.isHelpParam()) {
console.println(cliBundle.getString("help-param-header"));
ResourceBundle configBundle = PropertyResourceBundle.getBundle("ConfigMessages");
ConfigUtils.printParamDescriptionFromConfigSchema(Config.class, configBundle, console, 0);
System.exit(0);
}
final Config config = CliConfigUtils.readConfig(cliConfig);
if (cliConfig.isPrintConfig()) {
ConfigUtils.printYamlConfig(config, console);
System.exit(0);
}
if (cliConfig.isPrintXmlConfig()) {
ConfigUtils.printXmlConfig(config, console);
System.exit(0);
}
configureLogger(cliConfig, config);
config.getBackend().getBackendImplementation().accept(new BackendImplementationVisitor() {
@Override
public void visit(AbstractDerby value) {
parseToropassFile(value);
}
@Override
public void visit(AbstractPostgres value) {
parseToropassFile(value);
}
public void parseToropassFile(BackendPasswordConfig value) {
try {
ConfigUtils.parseToropassFile(value);
} catch (Exception ex) {
throw new SystemException(ex);
}
}
});
if (config.getProtocol().getMongo().getReplication() != null) {
for (AbstractReplication replication : config.getProtocol().getMongo().getReplication()) {
if (replication.getAuth().getUser() != null) {
HostAndPort syncSource = HostAndPort.fromString(replication.getSyncSource()).withDefaultPort(27017);
ConfigUtils.parseMongopassFile(new MongoPasswordConfig() {
@Override
public void setPassword(String password) {
replication.getAuth().setPassword(password);
}
@Override
public String getUser() {
return replication.getAuth().getUser();
}
@Override
public Integer getPort() {
return syncSource.getPort();
}
@Override
public String getPassword() {
return replication.getAuth().getPassword();
}
@Override
public String getMongopassFile() {
return config.getProtocol().getMongo().getMongopassFile();
}
@Override
public String getHost() {
return syncSource.getHostText();
}
@Override
public String getDatabase() {
return replication.getAuth().getSource();
}
});
}
}
}
if (config.getBackend().isLike(AbstractPostgres.class)) {
AbstractPostgres postgres = config.getBackend().as(AbstractPostgres.class);
if (cliConfig.isAskForPassword()) {
console.print("Database user " + postgres.getUser() + " password:");
postgres.setPassword(readPwd());
}
} else if (config.getBackend().isLike(AbstractDerby.class)) {
AbstractDerby derby = config.getBackend().as(AbstractDerby.class);
if (cliConfig.isAskForPassword()) {
console.print("Database user " + derby.getUser() + " password:");
derby.setPassword(readPwd());
}
}
try {
Clock clock = Clock.systemDefaultZone();
Service server;
if (config.getProtocol().getMongo().getReplication() == null || config.getProtocol().getMongo().getReplication().isEmpty()) {
Service toroDbServer = ToroDbBootstrap.createStandaloneService(config, clock);
toroDbServer.startAsync();
toroDbServer.awaitRunning();
server = toroDbServer;
} else {
throw new UnsupportedOperationException("Replication not supported yet!");
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
server.stopAsync();
server.awaitTerminated();
}));
} catch (CreationException ex) {
ex.getErrorMessages().stream().forEach(m -> {
if (m.getCause() != null) {
LOGGER.error(m.getCause().getMessage());
} else {
LOGGER.error(m.getMessage());
}
});
System.exit(1);
} catch (Throwable ex) {
LOGGER.error("Fatal error on initialization", ex);
Throwable rootCause = Throwables.getRootCause(ex);
String causeMessage = rootCause.getMessage();
JCommander.getConsole().println("Fatal error while ToroDB was starting: " + causeMessage);
System.exit(1);
}
}
use of com.beust.jcommander.JCommander in project disunity by ata4.
the class DisUnityCli method main.
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
LogUtils.configure();
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true)) {
JCommander jc = new JCommander();
DisUnityRoot root = new DisUnityRoot();
root.init(jc, out);
jc.setProgramName(DisUnity.getProgramName());
jc.addObject(root);
jc.parse(args);
root.run();
} catch (ParameterException ex) {
L.log(Level.WARNING, "Parameter error: {0}", ex.getMessage());
} catch (Throwable t) {
L.log(Level.SEVERE, "Fatal error", t);
}
}
Aggregations