Example usage for org.apache.commons.cli OptionBuilder create

List of usage examples for org.apache.commons.cli OptionBuilder create

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionBuilder create.

Prototype

public static Option create(String opt) throws IllegalArgumentException 

Source Link

Document

Create an Option using the current settings and with the specified Option char.

Usage

From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.spi.CliOptionsBuilder.java

public Option create(char opt) {
    return OptionBuilder.create(opt);
}

From source file:com.kaaprotech.satu.util.CmdLineUtil.java

@SuppressWarnings("static-access")
private static Options getOptions() {
    final Options options = new Options();
    OptionBuilder.create("init");
    final Option in = OptionBuilder.withArgName(IN).hasArgs().withDescription("One or more model files")
            .isRequired().create(IN);/*from   w  w w .  j  a  v  a  2 s  .com*/
    options.addOption(in);
    final Option out = OptionBuilder.withArgName(OUT).hasArg().withDescription("Output root directory")
            .isRequired().create(OUT);
    options.addOption(out);
    final Option json = OptionBuilder.withArgName(JSON).hasArg(false)
            .withDescription("Add json support to generated code").isRequired(false).create(JSON);
    options.addOption(json);
    return options;
}

From source file:de.weltraumschaf.groundzero.opt.commons.OptionsConfiguration.java

/**
 * Initializes {@link #options} with all information the options parser needs.
 *//*from w w w  . j  av  a2s.c  o  m*/
public OptionsConfiguration() {
    super();
    // w/ argument
    OptionBuilder.withDescription(OptionDescriptor.PATH_PREFIX.getDescription());
    OptionBuilder.withArgName("PATH");
    OptionBuilder.hasArg();
    OptionBuilder.withLongOpt(OptionDescriptor.PATH_PREFIX.getLongOption());
    options.addOption(OptionBuilder.create(OptionDescriptor.PATH_PREFIX.getShortOption()));
    OptionBuilder.withDescription(OptionDescriptor.INPUT_ENCODING.getDescription());
    OptionBuilder.withArgName("ENCODING");
    OptionBuilder.hasArg();
    OptionBuilder.withLongOpt(OptionDescriptor.INPUT_ENCODING.getLongOption());
    options.addOption(OptionBuilder.create(OptionDescriptor.INPUT_ENCODING.getShortOption()));
    OptionBuilder.withDescription(OptionDescriptor.OUTPUT_ENCODING.getDescription());
    OptionBuilder.withArgName("ENCODING");
    OptionBuilder.hasArg();
    OptionBuilder.withLongOpt(OptionDescriptor.OUTPUT_ENCODING.getLongOption());
    options.addOption(OptionBuilder.create(OptionDescriptor.OUTPUT_ENCODING.getShortOption()));

    // w/o argument
    options.addOption(OptionDescriptor.DEBUG.getShortOption(), OptionDescriptor.DEBUG.getLongOption(), false,
            OptionDescriptor.DEBUG.getDescription());
    options.addOption(OptionDescriptor.HELP.getShortOption(), OptionDescriptor.HELP.getLongOption(), false,
            OptionDescriptor.HELP.getDescription());
    options.addOption(OptionDescriptor.VERSION.getShortOption(), OptionDescriptor.VERSION.getLongOption(),
            false, OptionDescriptor.VERSION.getDescription());
}

From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.spi.CliOptionsBuilder.java

public Option create(String opt) {
    return OptionBuilder.create(opt);
}

From source file:com.rockagen.commons.util.CLITest.java

@Test
@Ignore/*from   w ww.j  av a 2s  .  com*/
public void testCLI() {

    // create the Options
    Options options = new Options();
    options.addOption("h", "help", false, "print help for the command.");
    options.addOption("v", "verbose", false, "verbose");
    OptionBuilder.withArgName("property=value");
    OptionBuilder.hasArgs(2);
    OptionBuilder.withLongOpt("desc");
    OptionBuilder.withValueSeparator();
    OptionBuilder.withDescription("use value for given property");
    options.addOption(OptionBuilder.create("D"));

    OptionBuilder.withArgName("file1,file2...");
    OptionBuilder.hasArgs();
    OptionBuilder.withLongOpt("input");
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withDescription("file name");
    options.addOption(OptionBuilder.create("i"));

    String formatstr = "CLITest [-h/--help][-v/--verbose]..";
    try {
        String[] args = { "CLITest", "--help", "-v", "-s", "--desc", "name=value", "--input", "file1", "file2",
                "file3" };
        // parse the command line arguments
        CommandLine line = CmdUtil.parse(options, args);

        if (line.hasOption("h")) {
            CmdUtil.printHelp(formatstr, "weclome usa", options,
                    "If you hava some quesion,please mail to agen@rockagen.com");
        }
        if (line.hasOption("v")) {
            System.out.println("VERSION 0.0.1");
        }
        if (line.hasOption("D")) {
            System.out.println("hey,guys,you input " + ArrayUtil.toString(line.getOptionValues("D")));
        }
        if (line.hasOption("i")) {
            System.out.println("hey,guys,you input " + ArrayUtil.toString(line.getOptionValues("i")));
        } else {
            CmdUtil.printHelp(formatstr, options);
        }
    } catch (ParseException exp) {
        CmdUtil.printHelp(formatstr, options);
        System.err.println();
        System.err.println(exp.getMessage());
    }

}

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();//  w  ww.  ja  v a 2s .  c  o m
    this.option = OptionBuilder.create(flag);
}

From source file:chibi.gemmaanalysis.cli.deprecated.PARMapper.java

@SuppressWarnings("static-access")
@Override/*  w  w  w . ja  va 2  s .co  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:com.amazonaws.services.dynamodbv2.online.index.ViolationDetector.java

public static void main(String[] args) {
    CommandLine commandLine;/*w w  w  .j  a  v  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:chibi.gemmaanalysis.GeneExpressionProfileWriterCLI.java

@Override
protected void buildOptions() {
    super.buildOptions();

    Option outFilePrefixOption = OptionBuilder.create('o');
    addOption(outFilePrefixOption);/* w  ww.  j  a  v a 2 s  .c  om*/
}

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();/* w  w w  .  j a v a 2 s .  co  m*/
    OptionBuilder.withDescription(description);
    return OptionBuilder.create(option);
}