use of org.apache.commons.cli.CommandLineParser in project databus by linkedin.
the class ClusterFileLoggingClient method processLocalArgs.
protected static String[] processLocalArgs(String[] cliArgs) throws IOException, ParseException {
CommandLineParser cliParser = new GnuParser();
Options cliOptions = constructCommandLineOptions();
CommandLine cmd = cliParser.parse(cliOptions, cliArgs, true);
// Options here has to be up front
if (cmd.hasOption(CLUSTER_NAME_OPT_NAME)) {
String cluster = cmd.getOptionValue(CLUSTER_NAME_OPT_NAME);
String[] clusters = cluster.split(",");
_clusters = Arrays.asList(clusters);
LOG.info("Cluster Name = " + _clusters);
}
if (cmd.hasOption(RELAY_HOST_OPT_NAME)) {
_relayHost = cmd.getOptionValue(RELAY_HOST_OPT_NAME);
LOG.info("Relay Host = " + _relayHost);
}
if (cmd.hasOption(RELAY_PORT_OPT_NAME)) {
_relayPort = cmd.getOptionValue(RELAY_PORT_OPT_NAME);
LOG.info("Relay Port = " + _relayPort);
}
if (cmd.hasOption(EVENT_DUMP_FILE_OPT_NAME)) {
_eventDumpFile = cmd.getOptionValue(EVENT_DUMP_FILE_OPT_NAME);
LOG.info("Saving event dump to file: " + _eventDumpFile);
}
if (cmd.hasOption(VALUE_DUMP_FILE_OPT_NAME)) {
_valueDumpFile = cmd.getOptionValue(VALUE_DUMP_FILE_OPT_NAME);
LOG.info("Saving event value dump to file: " + _valueDumpFile);
}
if (cmd.hasOption(HTTP_PORT_OPT_NAME)) {
_httpPort = cmd.getOptionValue(HTTP_PORT_OPT_NAME);
LOG.info("Consumer http port = " + _httpPort);
}
if (cmd.hasOption(JMX_SERVICE_PORT_OPT_NAME)) {
_jmxServicePort = cmd.getOptionValue(JMX_SERVICE_PORT_OPT_NAME);
LOG.info("Consumer JMX Service port = " + _jmxServicePort);
}
if (cmd.hasOption(BOOTSTRAP_HOST_OPT_NAME)) {
_bootstrapHost = cmd.getOptionValue(BOOTSTRAP_HOST_OPT_NAME);
LOG.info("Bootstrap Server = " + _bootstrapHost);
}
if (cmd.hasOption(BOOTSTRAP_PORT_OPT_NAME)) {
_bootstrapPort = cmd.getOptionValue(BOOTSTRAP_PORT_OPT_NAME);
LOG.info("Bootstrap Server Port = " + _bootstrapPort);
}
if (cmd.hasOption(EVENT_PATTERN_OPT_NAME)) {
_eventPattern = cmd.getOptionValue(EVENT_PATTERN_OPT_NAME);
LOG.info("Event pattern = " + _eventPattern);
}
if (_bootstrapHost != null || _bootstrapPort != null) {
_enableBootStrap = true;
}
// return what left over args
return cmd.getArgs();
}
use of org.apache.commons.cli.CommandLineParser in project databus by linkedin.
the class CheckpointSerializerMain method parseArgs.
private static void parseArgs(String[] args) throws Exception {
CommandLineParser cliParser = new GnuParser();
Options options = createOptions();
CommandLine cmd = null;
try {
cmd = cliParser.parse(options, args);
} catch (ParseException pe) {
throw new RuntimeException("failed to parse command-line options.", pe);
}
if (cmd.hasOption(HELP_OPT_CHAR) || 0 == cmd.getOptions().length) {
printCliHelp(options);
System.exit(0);
}
try {
_action = Action.valueOf(cmd.getOptionValue(ACTION_OPT_CHAR).toUpperCase());
} catch (Exception e) {
throw new RuntimeException("invalid action: " + cmd.getOptionValue(ACTION_OPT_CHAR), e);
}
if (!cmd.hasOption(SOURCES_OPT_CHAR)) {
throw new RuntimeException("expected sources list; see --help for more info");
}
String sourcesListStr = cmd.getOptionValue(SOURCES_OPT_CHAR);
_sources = sourcesListStr.split(",");
if (null == _sources || 0 == _sources.length) {
throw new RuntimeException("empty sources list");
}
for (int i = 0; i < _sources.length; ++i) _sources[i] = _sources[i].trim();
if (Action.PRINT != _action && !cmd.hasOption(CLIENT_PROPS_FILE_OPT_CHAR) && !cmd.hasOption(CP3_PROPS_FILE_OPT_CHAR)) {
throw new RuntimeException("expected client or CP3 configuration; see --help for more info");
}
String defaultPropPrefix = null;
if (cmd.hasOption(CLIENT_PROPS_FILE_OPT_CHAR)) {
try {
_clientProps = loadProperties(cmd.getOptionValue(CLIENT_PROPS_FILE_OPT_CHAR));
defaultPropPrefix = "databus2.client";
} catch (Exception e) {
throw new RuntimeException("unable to load client properties", e);
}
} else if (cmd.hasOption(CP3_PROPS_FILE_OPT_CHAR)) {
try {
_cp3Props = loadProperties(cmd.getOptionValue(CP3_PROPS_FILE_OPT_CHAR));
defaultPropPrefix = "databus2.client.checkpointPersistence";
} catch (Exception e) {
throw new RuntimeException("unable to load CP3 properties", e);
}
}
_propPrefix = cmd.hasOption(PROPS_PREFIX_OPT_CHAR) ? cmd.getOptionValue(PROPS_PREFIX_OPT_CHAR) : defaultPropPrefix;
if (null != _propPrefix && !_propPrefix.endsWith(".")) {
_propPrefix = _propPrefix + ".";
}
if (!cmd.hasOption(ACTION_OPT_CHAR)) {
throw new RuntimeException("action expected; see --help for more info");
}
_scn = parseLongOption(cmd, SCN_OPT_CHAR, "sequence number");
_sinceScn = parseLongOption(cmd, SINCE_SCN_OPT_CHAR, "last sequence number");
_startScn = parseLongOption(cmd, START_SCN_OPT_CHAR, "start sequence number");
_targetScn = parseLongOption(cmd, TARGET_SCN_OPT_CHAR, "target sequence number");
if (cmd.hasOption(TYPE_OPT_CHAR)) {
try {
_cpType = DbusClientMode.valueOf(cmd.getOptionValue(TYPE_OPT_CHAR).toUpperCase());
} catch (Exception e) {
throw new RuntimeException("invalid checkpoint type:" + cmd.getOptionValue(TYPE_OPT_CHAR), e);
}
}
if (cmd.hasOption(BOOTSTRAP_SOURCE_OPT_CHAR)) {
_bootstrapSource = cmd.getOptionValue(BOOTSTRAP_SOURCE_OPT_CHAR);
}
}
use of org.apache.commons.cli.CommandLineParser in project rest.li by linkedin.
the class RestLiSnapshotCompatibilityChecker method main.
public static void main(String[] args) {
final Options options = new Options();
options.addOption("h", "help", false, "Print help");
options.addOption(OptionBuilder.withArgName("compatibility_level").withLongOpt("compat").hasArg().withDescription("Compatibility level " + listCompatLevelOptions()).create('c'));
options.addOption(OptionBuilder.withLongOpt("report").withDescription("Prints a report at the end of the execution that can be parsed for reporting to other tools").create("report"));
final String cmdLineSyntax = RestLiSnapshotCompatibilityChecker.class.getCanonicalName() + " [pairs of <prevRestspecPath currRestspecPath>]";
final CommandLineParser parser = new PosixParser();
final CommandLine cmd;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
new HelpFormatter().printHelp(cmdLineSyntax, options, true);
System.exit(255);
// to suppress IDE warning
return;
}
final String[] targets = cmd.getArgs();
if (cmd.hasOption('h') || targets.length < 2 || targets.length % 2 != 0) {
new HelpFormatter().printHelp(cmdLineSyntax, options, true);
System.exit(255);
}
final String compatValue;
if (cmd.hasOption('c')) {
compatValue = cmd.getOptionValue('c');
} else {
compatValue = CompatibilityLevel.DEFAULT.name();
}
final CompatibilityLevel compat;
try {
compat = CompatibilityLevel.valueOf(compatValue.toUpperCase());
} catch (IllegalArgumentException e) {
new HelpFormatter().printHelp(cmdLineSyntax, options, true);
System.exit(255);
return;
}
final String resolverPath = System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH);
final RestLiSnapshotCompatibilityChecker checker = new RestLiSnapshotCompatibilityChecker();
checker.setResolverPath(resolverPath);
for (int i = 1; i < targets.length; i += 2) {
String prevTarget = targets[i - 1];
String currTarget = targets[i];
checker.checkCompatibility(prevTarget, currTarget, compat, prevTarget.endsWith(".restspec.json"));
}
String summary = checker.getInfoMap().createSummary();
if (compat != CompatibilityLevel.OFF && summary.length() > 0) {
System.out.println(summary);
}
if (cmd.hasOption("report")) {
System.out.println(new CompatibilityReport(checker.getInfoMap(), compat).createReport());
System.exit(0);
}
System.exit(checker.getInfoMap().isCompatible(compat) ? 0 : 1);
}
use of org.apache.commons.cli.CommandLineParser in project rest.li by linkedin.
the class RestLiSnapshotExporterCmdLineApp method main.
/**
* @param args restliexporter -sourcepath sourcepath -resourcepackages packagenames [-name api_name] [-outdir outdir]
*/
public static void main(String[] args) {
CommandLine cl = null;
try {
final CommandLineParser parser = new GnuParser();
cl = parser.parse(OPTIONS, args);
} catch (ParseException e) {
System.err.println("Invalid arguments: " + e.getMessage());
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("restliexporter -sourcepath sourcepath [-resourcepackages packagenames] [-resourceclasses classnames]" + "[-name api_name] [-outdir outdir]", OPTIONS);
System.exit(0);
}
final String resolverPath = System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH);
try {
final RestLiSnapshotExporter exporter = new RestLiSnapshotExporter();
exporter.setResolverPath(resolverPath);
exporter.export(cl.getOptionValue("name"), null, cl.getOptionValues("sourcepath"), cl.getOptionValues("resourcepackages"), cl.getOptionValues("resourceClasses"), cl.getOptionValue("outdir", "."), AdditionalDocProvidersUtil.findDocProviders(log, cl.hasOption("loadAdditionalDocProviders")));
} catch (Throwable e) {
log.error("Error writing Snapshot files", e);
System.out.println("Error writing Snapshot files:\n" + e);
System.exit(1);
}
}
use of org.apache.commons.cli.CommandLineParser in project rest.li by linkedin.
the class RestLiResourceModelExporterCmdLineApp method main.
/**
* @param args restliexporter -sourcepath sourcepath -resourcepackages packagenames [-name api_name] [-outdir outdir]
*/
public static void main(String[] args) {
// args = new String[] {"-name", "groups",
// "-resourcepackages", "com.linkedin.groups.server.rest1.impl com.linkedin.groups.server.rest2.impl ",
// "-resourceclasses", "com.linkedin.groups.server.restX.impl.FooResource",
// "-sourcepath", "src/main/java",
// "-outdir", "src/codegen/idl",
// "-split"};
CommandLine cl = null;
try {
final CommandLineParser parser = new GnuParser();
cl = parser.parse(OPTIONS, args);
} catch (ParseException e) {
System.err.println("Invalid arguments: " + e.getMessage());
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("restliexporter -sourcepath sourcepath [-resourcepackages packagenames] [-resourceclasses classnames]" + "[-name api_name] [-outdir outdir]", OPTIONS);
System.exit(0);
}
try {
new RestLiResourceModelExporter().export(cl.getOptionValue("name"), null, cl.getOptionValues("sourcepath"), cl.getOptionValues("resourcepackages"), cl.getOptionValues("resourceclasses"), cl.getOptionValue("outdir", "."), AdditionalDocProvidersUtil.findDocProviders(log, cl.hasOption("loadAdditionalDocProviders")));
} catch (Throwable e) {
log.error("Error writing IDL files", e);
System.exit(1);
}
}
Aggregations