List of usage examples for org.apache.commons.cli OptionBuilder hasArg
public static OptionBuilder hasArg()
From source file:com.amazonaws.services.dynamodbv2.online.index.ViolationDetector.java
public static void main(String[] args) { CommandLine commandLine;/*from ww w . ja v a2 s.com*/ 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:chibi.gemmaanalysis.cli.deprecated.PARMapper.java
@SuppressWarnings("static-access") @Override// www. j a v a 2s .c o m protected void buildOptions() { Option taxonOption = OptionBuilder.hasArg().isRequired().withDescription("taxon name") .withDescription("taxon to use").withLongOpt("taxon").create('t'); addOption(taxonOption); Option useStrandOption = OptionBuilder.create("useStrand"); addOption(useStrandOption); }
From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.spi.CliOptionsBuilder.java
public CliOptionsBuilder hasArg() { OptionBuilder.hasArg(); return this; }
From source file:com.cjmcgraw.markupvalidator.args.Arguments.java
Arguments(String flag, String name, String msg, boolean requiresArg) { OptionBuilder.withLongOpt(name).withDescription(msg); if (requiresArg) OptionBuilder.hasArg(); this.option = OptionBuilder.create(flag); }
From source file:chibi.gemmaanalysis.AbstractGeneCoexpressionManipulatingCLI.java
@SuppressWarnings("static-access") @Override//from w ww .j av a2s .co m protected void buildOptions() { super.buildOptions(); Option queryGeneFileOption = OptionBuilder.hasArg() .withDescription("Query file containing list of gene official symbols").withArgName("File name") .withLongOpt("queryGeneFile").create(); addOption(queryGeneFileOption); Option queryGeneOption = OptionBuilder.hasArgs().withArgName("Gene symbol(s)") .withDescription("The query gene(s)").withLongOpt("queryGene").create(); addOption(queryGeneOption); Option targetFileOption = OptionBuilder.hasArg().withArgName("File name") .withDescription("File containing list of target gene official symbols") .withLongOpt("targetGeneFile").create(); addOption(targetFileOption); Option targetGeneOption = OptionBuilder.hasArgs().withArgName("Gene symbol(s)") .withDescription("The target gene(s)").withLongOpt("targetGene").create(); addOption(targetGeneOption); }
From source file:com.huawei.streaming.cql.OptionsProcessor.java
@SuppressWarnings("static-access") private void initOptions() { // -f <query-file> options.addOption(OptionBuilder.hasArg().withLongOpt("file").withArgName("filename") .withDescription("CQL from files").create('f')); // [-S|--silent] options.addOption(new Option("s", "silent", false, "Silent mode in interactive shell")); // [-H|--help] options.addOption(new Option("h", "help", false, "Print help information")); }
From source file:eu.stratosphere.myriad.driver.MyriadDriverFrontend.java
public MyriadDriverFrontend() { // dgen-install-dir this.options = new Options(); // scaling-factor OptionBuilder.hasArg(); OptionBuilder.withArgName("double"); OptionBuilder.withDescription("scaling factor (s=1 generates 1GB)"); OptionBuilder.withLongOpt("scaling-factor"); this.options.addOption(OptionBuilder.create('s')); // dataset-id OptionBuilder.hasArg();//from w w w .j a va2 s . co m OptionBuilder.withArgName("string"); OptionBuilder.withDescription("ID of the generated Myriad dataset"); OptionBuilder.withLongOpt("dataset-id"); this.options.addOption(OptionBuilder.create('m')); // node-count OptionBuilder.hasArg(); OptionBuilder.withArgName("int"); OptionBuilder.withDescription("degree of parallelism (i.e. total number of partitions)"); OptionBuilder.withArgName("node-count"); this.options.addOption(OptionBuilder.create('N')); // output-base OptionBuilder.hasArg(); OptionBuilder.withArgName("path"); OptionBuilder.withDescription("base path for writing the output"); OptionBuilder.withLongOpt("output-base"); this.options.addOption(OptionBuilder.create('o')); // execute-stages OptionBuilder.hasArgs(); OptionBuilder.withArgName("stagename"); OptionBuilder.withDescription("specify specific stages to be executed"); OptionBuilder.withLongOpt("execute-stage"); this.options.addOption(OptionBuilder.create('x')); }
From source file:com.dm.estore.server.CommandLineOptions.java
private Option createOption(final String argument, final String description, final String option) { OptionBuilder.withArgName(argument); OptionBuilder.hasArg(); OptionBuilder.withDescription(description); return OptionBuilder.create(option); }
From source file:galen.api.server.GalenApiServer.java
private static Options defineCommandOptions() { Option helpOption = new Option("help", "h", false, "explains usage"); Option runOption = OptionBuilder.hasArg().withArgName("port") .withDescription("Runs the server on specified port").withLongOpt("r").create("run"); Options options = new Options(); options.addOption(helpOption).addOption(runOption); return options; }
From source file:net.jsign.PESignerCLI.java
PESignerCLI() { options = new Options(); options.addOption(OptionBuilder.hasArg().withLongOpt("keystore").withArgName("FILE") .withDescription("The keystore file").withType(File.class).create('s')); options.addOption(OptionBuilder.hasArg().withLongOpt("storepass").withArgName("PASSWORD") .withDescription("The password to open the keystore").create()); options.addOption(OptionBuilder.hasArg().withLongOpt("storetype").withArgName("TYPE").withDescription( "The type of the keystore:\n- JKS: Java keystore (.jks files)\n- PKCS12: Standard PKCS#12 keystore (.p12 or .pfx files)\n") .create());//w w w . jav a 2 s. c o m options.addOption(OptionBuilder.hasArg().withLongOpt("alias").withArgName("NAME") .withDescription("The alias of the certificate used for signing in the keystore.").create('a')); options.addOption(OptionBuilder.hasArg().withLongOpt("keypass").withArgName("PASSWORD").withDescription( "The password of the private key. When using a keystore, this parameter can be omitted if the keystore shares the same password.") .create()); options.addOption(OptionBuilder.hasArg().withLongOpt("keyfile").withArgName("FILE") .withDescription("The file containing the private key. Only PVK files are supported. ") .withType(File.class).create()); options.addOption(OptionBuilder.hasArg().withLongOpt("certfile").withArgName("FILE") .withDescription("The file containing the PKCS#7 certificate chain\n(.p7b or .spc files).") .withType(File.class).create('c')); options.addOption(OptionBuilder.hasArg().withLongOpt("keyfile").withArgName("FILE") .withDescription("The file containing the private key. Only PVK files are supported. ") .withType(File.class).create()); options.addOption(OptionBuilder.hasArg().withLongOpt("alg").withArgName("ALGORITHM") .withDescription("The digest algorithm (SHA-1 or SHA-256)").create('d')); options.addOption(OptionBuilder.hasArg().withLongOpt("tsaurl").withArgName("URL") .withDescription("The URL of the timestamping authority.").create('t')); options.addOption(OptionBuilder.hasArg().withLongOpt("tsmode").withArgName("MODE") .withDescription("The timestamping mode (RFC3161 or Authenticode)").create('m')); options.addOption(OptionBuilder.hasArg().withLongOpt("name").withArgName("NAME") .withDescription("The name of the application").create('n')); options.addOption(OptionBuilder.hasArg().withLongOpt("url").withArgName("URL") .withDescription("The URL of the application").create('u')); options.addOption(OptionBuilder.withLongOpt("help").withDescription("Print the help").create('h')); }