use of org.apache.commons.cli.HelpFormatter in project databus by linkedin.
the class CheckpointSerializerMain method printCliHelp.
private static void printCliHelp(Options cliOptions) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.setWidth(120);
helpFormatter.printHelp("java " + CheckpointSerializerMain.class.getName(), cliOptions);
}
use of org.apache.commons.cli.HelpFormatter 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.HelpFormatter 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.HelpFormatter 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);
}
}
use of org.apache.commons.cli.HelpFormatter in project Cloud9 by lintool.
the class BigramCount method run.
/**
* Runs this tool.
*/
@SuppressWarnings({ "static-access" })
public int run(String[] args) throws Exception {
Options options = new Options();
options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));
options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT));
options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of reducers").create(NUM_REDUCERS));
CommandLine cmdline;
CommandLineParser parser = new GnuParser();
try {
cmdline = parser.parse(options, args);
} catch (ParseException exp) {
System.err.println("Error parsing command line: " + exp.getMessage());
return -1;
}
if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT)) {
System.out.println("args: " + Arrays.toString(args));
HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(120);
formatter.printHelp(this.getClass().getName(), options);
ToolRunner.printGenericCommandUsage(System.out);
return -1;
}
String inputPath = cmdline.getOptionValue(INPUT);
String outputPath = cmdline.getOptionValue(OUTPUT);
int reduceTasks = cmdline.hasOption(NUM_REDUCERS) ? Integer.parseInt(cmdline.getOptionValue(NUM_REDUCERS)) : 1;
LOG.info("Tool name: " + BigramCount.class.getSimpleName());
LOG.info(" - input path: " + inputPath);
LOG.info(" - output path: " + outputPath);
LOG.info(" - num reducers: " + reduceTasks);
Job job = Job.getInstance(getConf());
job.setJobName(BigramCount.class.getSimpleName());
job.setJarByClass(BigramCount.class);
job.setNumReduceTasks(reduceTasks);
FileInputFormat.setInputPaths(job, new Path(inputPath));
FileOutputFormat.setOutputPath(job, new Path(outputPath));
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setOutputFormatClass(SequenceFileOutputFormat.class);
job.setMapperClass(MyMapper.class);
job.setCombinerClass(MyReducer.class);
job.setReducerClass(MyReducer.class);
// Delete the output directory if it exists already.
Path outputDir = new Path(outputPath);
FileSystem.get(getConf()).delete(outputDir, true);
long startTime = System.currentTimeMillis();
job.waitForCompletion(true);
System.out.println("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds");
return 0;
}
Aggregations