List of usage examples for org.apache.commons.cli OptionBuilder withDescription
public static OptionBuilder withDescription(String newDescription)
From source file:com.amazonaws.services.dynamodbv2.online.index.ViolationDetector.java
public static void main(String[] args) { CommandLine commandLine;/*from w w w . j av a 2 s. c o m*/ org.apache.commons.cli.Options options = new org.apache.commons.cli.Options(); CommandLineParser parser = new GnuParser(); HelpFormatter formatter = new HelpFormatter(); Option optionHelp = new Option("h", "help", false, "Help and usage information"); OptionBuilder.withArgName("keep/delete"); OptionBuilder.withLongOpt("detect"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Detect violations on given table. " + "\nwith 'keep', violations will be kept and recorded;" + "\nwith 'delete', violations will be deleted and recorded."); Option optionDetection = OptionBuilder.create("t"); OptionBuilder.withArgName("update/delete"); OptionBuilder.withLongOpt("correct"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Correct violations based on records on correction input file." + "\nwith 'delete', records on input file will be deleted from the table;" + "\nwith 'update', records on input file will be updated to the table."); Option optionCorrection = OptionBuilder.create("c"); OptionBuilder.withArgName("configFilePath"); OptionBuilder.withLongOpt("configFilePath"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Path of the config file. \nThis option is required for both detection and correction."); Option optionConfigFilePath = OptionBuilder.create("p"); options.addOption(optionConfigFilePath); options.addOption(optionDetection); options.addOption(optionCorrection); options.addOption(optionHelp); try { ViolationDetector detector = new ViolationDetector(); commandLine = parser.parse(options, args); /** Violation detection */ if (commandLine.hasOption("t")) { if (!commandLine.hasOption("p")) { logger.error("Config file path not provided. Exiting..."); formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/); System.exit(1); } String configFilePath = commandLine.getOptionValue("p"); detector.setConfigFile(configFilePath); String detectOption = commandLine.getOptionValue("t"); if (detectOption.compareTo("delete") == 0) { confirmDelete(); detector.initDetection(); detector.violationDetection(true); } else if (detectOption.compareTo("keep") == 0) { detector.initDetection(); detector.violationDetection(false); } else { String errMessage = "Invalid options " + detectOption + " for 't/detect'"; logger.error(errMessage + ". Exiting..."); formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/); System.exit(1); } return; } /** Violation correction */ if (commandLine.hasOption("c")) { if (!commandLine.hasOption("p")) { logger.error("Config file path not provided. Exiting..."); formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/); System.exit(1); } String configFilePath = commandLine.getOptionValue("p"); detector.setConfigFile(configFilePath); String correctOption = commandLine.getOptionValue("c"); if (correctOption.compareTo("delete") == 0) { confirmDelete(); detector.initCorrection(); detector.violationCorrection(true, false /* useConditionalUpdate */); } else if (correctOption.compareTo("update") == 0) { detector.initCorrection(); boolean useConditionalUpdate = getUseConditionalUpdateOptionFromConsole(); detector.violationCorrection(false, useConditionalUpdate); } else { String errMessage = "Invalid options " + correctOption + " for 'c/correct'"; logger.error(errMessage + ". Exiting..."); formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/); System.exit(1); } return; } /** Help information */ if (commandLine.hasOption("h")) { formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/); return; } /** Error: print usage and exit */ String errMessage = "Invalid options, check usage"; logger.error(errMessage + ". Exiting..."); formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/); System.exit(1); } catch (IllegalArgumentException iae) { logger.error("Exception!", iae); System.exit(1); } catch (ParseException e) { logger.error("Exception!", e); formatter.printHelp(TOOL_USAGE_WIDTH, TOOL_USAGE, null /*header*/, options, null /*footer*/); System.exit(1); } }
From source file:commandline.CommandLineInterface.java
@SuppressWarnings("static-access") public CommandLineInterface(String[] args) { // create the Options Options options = new Options(); // create the command line parser CommandLineParser parser = new GnuParser(); Option port = OptionBuilder.withArgName("port").hasArg().isRequired().withDescription("Port Number") .create("s"); Option localWorker = OptionBuilder.withArgName("N_workers").hasArg() .withDescription("Run local worker threads").create("lw"); Option remoteWorker = OptionBuilder.withDescription("Run remote worker").create("rw"); options.addOption(port);/* www.ja v a 2s .c o m*/ options.addOption(localWorker); options.addOption(remoteWorker); try { // parse the command line arguments command = parser.parse(options, args); } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); } }
From source file:com.tractionsoftware.reshoot.Reshoot.java
private static CommandLine parseCommandLine(String[] args) { CommandLineParser parser = new GnuParser(); org.apache.commons.cli.Options options = new org.apache.commons.cli.Options(); // create the command-line options Option chrome = OptionBuilder.withDescription("use Chrome (for retina screenshots on retina displays)") .withLongOpt("chrome").create(); Option firefox = OptionBuilder.withDescription("use Firefox (for full scrollheight screenshots)") .withLongOpt("firefox").create(); options.addOption(chrome);/* w w w . j ava 2 s . com*/ options.addOption(firefox); // attempt to parse them, printing help if it fails try { CommandLine cmd = parser.parse(options, args); // make sure we have some files to process if (cmd.getArgList().isEmpty()) { showUsageAndExit(options); } return cmd; } catch (ParseException e) { showUsageAndExit(options); } return null; }
From source file:jlite.cli.ProxyDestroy.java
private static Options setupOptions() { Options options = new Options(); options.addOption(OptionBuilder.withDescription("displays usage").create("help")); options.addOption(OptionBuilder.withArgName("proxyfile").withDescription("non-standard location of proxy") .hasArg().create("file")); options.addOption(OptionBuilder.withArgName("xml").withDescription("output as xml").create("xml")); return options; }
From source file:it.crs4.seal.demux.DemuxOptionParser.java
@SuppressWarnings("static") // for OptionBuilder public DemuxOptionParser() { super(ConfigSection, "seal demux"); sampleSheetOpt = OptionBuilder.withDescription("Sample sheet for the experiment").hasArg() .withArgName("FILE").withLongOpt("sample-sheet").create("s"); options.addOption(sampleSheetOpt);/*w w w .ja v a 2 s. c o m*/ laneContentOpt = OptionBuilder.withDescription("create LaneContent files") .withLongOpt("create-lane-content").create("l"); createLaneContent = false; options.addOption(laneContentOpt); maxTagMismatchesOpt = OptionBuilder .withDescription("Maximum number of acceptable barcode substitution errors (default: 0)").hasArg() .withArgName("N").withLongOpt("mismatches").create("m"); maxTagMismatches = 0; // default value options.addOption(maxTagMismatchesOpt); noIndexReadsOpt = OptionBuilder .withDescription("Dataset doesn't contain index reads. Sort reads only by lane (default: false)") .withLongOpt("no-index").create("ni"); noIndexReads = false; // default value options.addOption(noIndexReadsOpt); separateReadsOpt = OptionBuilder .withDescription("Generate separate directories for each read number (default: false)") .withLongOpt("separate-reads").create("sepr"); separateReads = false; // default value options.addOption(separateReadsOpt); this.setMinReduceTasks(1); this.setAcceptedInputFormats(new String[] { "qseq", "fastq" }); this.setAcceptedOutputFormats(new String[] { "qseq", "fastq" }); }
From source file:ezbake.services.search.SSRServer.java
private static Option buildOption(String desc, char opt) { return OptionBuilder.withDescription(desc).hasArg().isRequired().create(opt); }
From source file:jlite.cli.ProxyDelegate.java
private static Options setupOptions() { Options options = new Options(); options.addOption(OptionBuilder.withDescription("displays usage").create("help")); options.addOption(OptionBuilder.withArgName("id_string") .withDescription("delegation id (default is user name)").hasArg().create("d")); options.addOption(OptionBuilder.withArgName("service_URL").withDescription("WMProxy service endpoint") .hasArg().create("e")); options.addOption(OptionBuilder.withArgName("proxyfile") .withDescription("non-standard location of proxy cert").hasArg().create("proxypath")); options.addOption(OptionBuilder.withArgName("xml").withDescription("output as xml").create("xml")); return options; }
From source file:ezbake.services.search.SSRServer.java
private static Option buildOptional(String desc, char opt) { return OptionBuilder.withDescription(desc).hasArg().isRequired(false).create(opt); }
From source file:jlite.cli.JobCancel.java
private static Options setupOptions() { Options options = new Options(); options.addOption(OptionBuilder.withDescription("displays usage").create("help")); options.addOption(OptionBuilder.withArgName("file_path") .withDescription("select JobId(s) from the specified file").hasArg().create("i")); options.addOption(OptionBuilder.withArgName("service_URL").withDescription("WMProxy service endpoint") .hasArg().create("e")); options.addOption(OptionBuilder.withArgName("proxyfile") .withDescription("non-standard location of proxy cert").hasArg().create("proxypath")); options.addOption(OptionBuilder.withArgName("xml").withDescription("output as xml").create("xml")); return options; }
From source file:jlite.cli.JobOutput.java
private static Options setupOptions() { Options options = new Options(); options.addOption(OptionBuilder.withDescription("displays usage").create("help")); options.addOption(OptionBuilder.withArgName("file_path") .withDescription("select JobId(s) from the specified file").hasArg().create("i")); options.addOption(OptionBuilder.withArgName("service_URL").withDescription("WMProxy service endpoint") .hasArg().create("e")); options.addOption(OptionBuilder.withArgName("dir_path") .withDescription("store output files in the specified directory (default is CURRENT_DIR/JOB_ID)") .hasArg().create("dir")); options.addOption(/*from w w w .j a v a 2 s.c om*/ OptionBuilder.withDescription("do not purge job output after retrieval").create("nopurge")); options.addOption(OptionBuilder.withDescription("do not retrieve output files, just print their URIs") .create("list")); options.addOption(OptionBuilder.withArgName("proxyfile") .withDescription("non-standard location of proxy cert").hasArg().create("proxypath")); options.addOption(OptionBuilder.withArgName("xml").withDescription("output as xml").create("xml")); // options.addOption(OptionBuilder // .withArgName("protocol") // .withDescription("protocol to be used for file tranfer {gsiftp,https} (default is gsiftp)") // .hasArg() // .create("proto")); return options; }