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

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

Introduction

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

Prototype

public static OptionBuilder withLongOpt(String newLongopt) 

Source Link

Document

The next Option created will have the following long option value.

Usage

From source file:com.github.xwgou.namesurfer.cli.JSurferOptions.java

public JSurferOptions() {
    Option help = OptionBuilder.withLongOpt("help").withDescription("display this help text and exit").create();
    Option version = OptionBuilder.withLongOpt("version").withDescription("print program version and exit")
            .create();//w w  w .ja  v a  2  s  .co  m
    Option disable_buttons = OptionBuilder.withLongOpt("disable-buttons")
            .withDescription("disable the export and save buttons").create();

    Option r = new Option("r", "rules", true, "specify the word translation "
            + "rules as rules.properties. Example: " + "-r $yourpath/rules.properties");

    Option k = new Option("k", "key", true, "specify the keyword rules"
            + " translation as keywords.properties. Example: " + "-k $yourpath/keywords.properties");

    Option f = new Option("f", "fullscreen", false, "run in full screen mode");

    this.addOption(help);
    this.addOption(version);
    this.addOption(disable_buttons);
    this.addOption(r);
    this.addOption(k);
    this.addOption(f);
}

From source file:cognition.pipeline.commandline.CommandCoordinator.java

@Override
public void addOption(Options options) {
    options.addOption(OptionBuilder.withLongOpt("coordinator")
            .withDescription("Application runs as coordinator web server.").withArgName("coordinator")
            .create());/* w  ww.  ja va 2  s .  c  o m*/
}

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

/**
 * Initializes {@link #options} with all information the options parser needs.
 *//*  ww w  .j  av a2 s  .co  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:com.marklogic.shell.command.ls.java

public ls() {
    Option longOption = OptionBuilder.withLongOpt("long")
            .withDescription("List files in long format with permissions").create("l");

    options.addOption(longOption);//from   w w w  .j  a  v  a 2  s  .com
}

From source file:com.marklogic.shell.command.cp.java

public cp() {
    Option force = OptionBuilder.withLongOpt("force").withDescription("Copy even if the target document exists")
            .create("f");
    Option fromHost = OptionBuilder.withLongOpt("from-host")
            .withDescription("Host server and port to copy from (uses default database for that port)")
            .create("s");
    Option toHost = OptionBuilder.withLongOpt("to-host").hasArg()
            .withDescription("Target server and port to copy to (uses default database for that port)")
            .create("d");

    options.addOption(fromHost);/*from  ww w. j  ava2 s  .  c  om*/
    options.addOption(toHost);
    options.addOption(force);
}

From source file:info.jejking.opengeodb.neo4j.importer.ImporterRunner.java

@SuppressWarnings("static-access")
private static void initOptions() {
    options.addOption(OptionBuilder.withLongOpt("placeFile").withArgName("placeFilePath").hasArg()
            .withDescription("path to tab delimited place file").create("p"));

    options.addOption(OptionBuilder.withLongOpt("zipCodesFile").withArgName("zipCodesFilePath").hasArg()
            .withDescription("path to tab delimited zip code (PLZ) file").create("z"));

    options.addOption(OptionBuilder.withLongOpt("neoDir").withArgName("neoDirPath").hasArg()
            .withDescription("path to directory in which to create neo4j database").create("n"));

    options.addOption("h", "help", false, "prints this message");
}

From source file:com.maxl.java.aips2sqlite.Aips2Sqlite.java

/**
 * Adds an option into the command line parser
 * /*from  w  ww.  jav  a2  s  .c  o m*/
 * @param optionName - the option name
 * @param description - option descriptiuon
 * @param hasValue - if set to true, --option=value, otherwise, --option is a boolean
 * @param isMandatory - if set to true, the option must be provided.
 */
@SuppressWarnings("static-access")
static void addOption(Options opts, String optionName, String description, boolean hasValue,
        boolean isMandatory) {
    OptionBuilder opt = OptionBuilder.withLongOpt(optionName);
    opt = opt.withDescription(description);
    if (hasValue)
        opt = opt.hasArg();
    if (isMandatory)
        opt = opt.isRequired();
    opts.addOption(opt.create());
}

From source file:com.vectorization.server.master.Application.java

private static Options createOptions() {
    Options options = new Options();
    OptionBuilder.withLongOpt("help");
    OptionBuilder.withDescription("Print this message");
    Option help = OptionBuilder.create();
    options.addOption(help);/*from www.  j  ava  2  s  .co m*/
    options.addOption("P", "port", true, "Port number to use for connection");
    options.addOption("V", "version", false, "Output version information and exit.");
    return options;
}

From source file:com.amazonaws.services.dynamodbv2.online.index.ViolationDetector.java

public static void main(String[] args) {
    CommandLine commandLine;// w ww . j a v  a 2s . c om
    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:it.infodreams.syncpath.commands.Commander.java

public Commander() {
    Option help = new Option("help", "Print this help message");
    Option verbose = new Option("verbose", "Show more output information during process");
    Option version = new Option("version", "Show the version information");

    Option scan = OptionBuilder.withLongOpt("scan")
            .withDescription("Attempts full scan of a specified path and creates a report").create("c");

    Option pack = OptionBuilder.withLongOpt("pack").withDescription("Perform a packing process").create("p");

    Option unpack = OptionBuilder.withLongOpt("unpack").withDescription("Perform a packing process")
            .create("u");

    Option sourcePath = OptionBuilder.withArgName("path").hasArg()
            .withDescription("Path to use as source for operations.").withLongOpt("source-path").create("s");

    Option destPath = OptionBuilder.withArgName("path").hasArg()
            .withDescription("Path to use as destionation for operations.").withLongOpt("dest-path")
            .create("d");

    Option reportFile = OptionBuilder.withArgName("filename").hasArg()
            .withDescription("Report to use as source for packing operations.").withLongOpt("report")
            .create("r");

    Option splitSize = OptionBuilder.withArgName("size-in-bytes").hasArg()
            .withDescription("Size of each splitted package (0 for unlimited size).").withLongOpt("split-size")
            .create("t");

    options.addOption(help);/*  ww w .j  a  va 2  s.c o  m*/
    options.addOption(verbose);
    options.addOption(version);
    options.addOption(scan);
    options.addOption(sourcePath);
    options.addOption(destPath);
    options.addOption(reportFile);
    options.addOption(pack);
    options.addOption(splitSize);
    options.addOption(unpack);
}