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

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

Introduction

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

Prototype

public static OptionBuilder withDescription(String newDescription) 

Source Link

Document

The next Option created will have the specified description

Usage

From source file:org.fbk.cit.hlt.dirha.Annotator.java

public static void main(String[] args) throws Exception {
    String logConfig = System.getProperty("log-config");
    if (logConfig == null) {
        logConfig = "log-config.txt";
    }/* www  . j  a  v  a 2 s  .c o  m*/

    Options options = new Options();
    try {
        Option inputFileOpt = OptionBuilder.withArgName("file").hasArg()
                .withDescription("root of files from which to read the frame and role models").isRequired()
                .withLongOpt("model").create("m");
        Option gazetteerFileOpt = OptionBuilder.withArgName("file").hasArg().withDescription("gazetteer file")
                .isRequired().withLongOpt("gazetteer").create("g");
        Option evalFileOpt = OptionBuilder.withArgName("file").hasArg()
                .withDescription("evaluation (annotated gold) spreadsheet file in tsv format)")
                .withLongOpt("eval").create("e");
        Option reportFileOpt = OptionBuilder.withArgName("file").hasArg()
                .withDescription("file in which to write the evaluation report in tsv format")
                .withLongOpt("report").create("r");
        Option classifyFileOpt = OptionBuilder.withArgName("file").hasArg()
                .withDescription("annotate offline the specified file in one sentence per line format")
                .withLongOpt("annotate").create("a");
        Option outputFileOpt = OptionBuilder.withArgName("file").hasArg()
                .withDescription("file in which to write the annotated the offline annotation in tsv format")
                .withLongOpt("output").create("o");
        Option interactiveModeOpt = OptionBuilder.withDescription("enter in the interactive mode")
                .withLongOpt("interactive-mode").create("i");
        Option langOpt = OptionBuilder.withArgName("string").hasArg().withDescription("language").isRequired()
                .withLongOpt("lang").create("l");
        options.addOption(OptionBuilder.withDescription("trace mode").withLongOpt("trace").create());
        options.addOption(OptionBuilder.withDescription("debug mode").withLongOpt("debug").create());
        Option normalizeNumOpt = OptionBuilder.withDescription("normalize numerical FEs")
                .withLongOpt("normalize-fes").create("n");

        options.addOption("h", "help", false, "print this message");
        options.addOption("v", "version", false, "output version information and exit");

        options.addOption(inputFileOpt);
        options.addOption(interactiveModeOpt);
        options.addOption(evalFileOpt);
        options.addOption(gazetteerFileOpt);
        options.addOption(classifyFileOpt);
        options.addOption(outputFileOpt);
        options.addOption(reportFileOpt);
        options.addOption(langOpt);
        options.addOption(normalizeNumOpt);

        CommandLineParser parser = new PosixParser();
        CommandLine line = parser.parse(options, args);

        Properties defaultProps = new Properties();
        defaultProps.load(new InputStreamReader(new FileInputStream(logConfig), "UTF-8"));
        if (line.hasOption("trace")) {
            defaultProps.setProperty("log4j.rootLogger", "trace,stdout");
        } else if (line.hasOption("debug")) {
            defaultProps.setProperty("log4j.rootLogger", "debug,stdout");
        }

        PropertyConfigurator.configure(defaultProps);

        File gazetteerFile = new File(line.getOptionValue("gazetteer"));
        String iob2 = line.getOptionValue("model") + ".iob2";
        String frame = line.getOptionValue("model") + ".frame";
        String lang = line.getOptionValue("lang");

        Annotator annotator = new Annotator(iob2, frame, gazetteerFile, lang);
        annotator.normalizeNumericalFEs = line.hasOption("normalize-fes");
        if (line.hasOption("interactive-mode")) {
            annotator.interactive();
        }

        if (line.hasOption("annotate")) {
            File textFile = new File(line.getOptionValue("annotate"));
            List<Answer> list = annotator.classify(textFile);
            File fout, confOut;

            if (line.hasOption("output"))
                fout = new File(line.getOptionValue("output"));
            else
                fout = new File(textFile.getAbsoluteFile() + ".output.tsv");

            File evaluationReportFile;
            if (line.hasOption("report")) {
                evaluationReportFile = new File(line.getOptionValue("report"));
            } else {
                evaluationReportFile = new File(textFile.getAbsoluteFile() + ".report.tsv");
            }
            logger.info("output file: " + fout);
            annotator.write(list, fout);

            if (line.hasOption("eval")) {
                File evalFile = new File(line.getOptionValue("eval"));
                Evaluator evaluator = new Evaluator(evalFile, fout,
                        new File(line.getOptionValue("model") + ".frame.label"),
                        new File(line.getOptionValue("model") + ".iob2.label"));
                evaluator.write(evaluationReportFile);
            }
        }
    } catch (ParseException e) {
        // oops, something went wrong
        System.out.println("Parsing failed: " + e.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(400,
                "java -Dfile.encoding=UTF-8 -cp dist/dirha.jar org.fbk.cit.hlt.dirha.Annotator", "\n", options,
                "\n", true);
    }
}

From source file:org.fbk.cit.hlt.dirha.FrameTrainingSetToLibSvm.java

public static void main(String[] args) throws Exception {
    String logConfig = System.getProperty("log-config");
    if (logConfig == null) {
        logConfig = "log-config.txt";
    }/* ww  w .j  ava 2s  .co m*/

    Options options = new Options();
    try {
        options.addOption(OptionBuilder.withArgName("file").hasArg()
                .withDescription("file from which to read the frame training file in 4-column format")
                .isRequired().withLongOpt("training").create("t"));
        options.addOption(OptionBuilder.withArgName("file").hasArg()
                .withDescription("file from which to read the gazetteer tsv format").isRequired()
                .withLongOpt("gazetteer").create("g"));
        options.addOption(OptionBuilder.withDescription("trace mode").withLongOpt("trace").create());
        options.addOption(OptionBuilder.withDescription("debug mode").withLongOpt("debug").create());
        options.addOption("h", "help", false, "print this message");
        options.addOption("v", "version", false, "output version information and exit");

        CommandLineParser parser = new PosixParser();
        CommandLine line = parser.parse(options, args);

        Properties defaultProps = new Properties();
        defaultProps.load(new InputStreamReader(new FileInputStream(logConfig), "UTF-8"));
        //defaultProps.setProperty("log4j.rootLogger", "info,stdout");
        if (line.hasOption("trace")) {
            defaultProps.setProperty("log4j.rootLogger", "trace,stdout");
        } else if (line.hasOption("debug")) {
            defaultProps.setProperty("log4j.rootLogger", "debug,stdout");
        } else if (logConfig == null) {
            defaultProps.setProperty("log4j.rootLogger", "info,stdout");
        }
        PropertyConfigurator.configure(defaultProps);

        String training = line.getOptionValue("training");
        File featureFile = new File(training + ".frame.feat");
        File exampleFile = new File(training);
        File libsvmFile = new File(training + ".frame.svm");
        File labelFile = new File(training + ".frame.label");

        File gazetteerFile = new File(line.getOptionValue("gazetteer"));
        new FrameTrainingSetToLibSvm(featureFile, exampleFile, libsvmFile, labelFile, gazetteerFile).convert();
    } catch (ParseException e) {
        // oops, something went wrong
        System.out.println("Parsing failed: " + e.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(400,
                "java -Dfile.encoding=UTF-8 -cp dist/dirha.jar org.fbk.cit.hlt.dirha.FrameTrainingSetToLibSvm",
                "\n", options, "\n", true);
    }
}

From source file:org.fbk.cit.hlt.dirha.RoleTrainingSetToLibSvm.java

public static void main(String[] args) throws Exception {
    String logConfig = System.getProperty("log-config");
    if (logConfig == null) {
        logConfig = "log-config.txt";
    }//from   w w  w  . ja  v  a 2  s. co  m

    Options options = new Options();
    try {
        options.addOption(OptionBuilder.withArgName("file").hasArg()
                .withDescription("file from which to read the role training file in IOB2 format").isRequired()
                .withLongOpt("training").create("t"));
        options.addOption(OptionBuilder.withArgName("file").hasArg()
                .withDescription("file from which to read the gazetteer tsv format").isRequired()
                .withLongOpt("gazetteer").create("g"));
        options.addOption(OptionBuilder.withDescription("trace mode").withLongOpt("trace").create());
        options.addOption(OptionBuilder.withDescription("debug mode").withLongOpt("debug").create());
        options.addOption("h", "help", false, "print this message");
        options.addOption("v", "version", false, "output version information and exit");

        CommandLineParser parser = new PosixParser();
        CommandLine line = parser.parse(options, args);

        Properties defaultProps = new Properties();
        defaultProps.load(new InputStreamReader(new FileInputStream(logConfig), "UTF-8"));
        //defaultProps.setProperty("log4j.rootLogger", "info,stdout");
        if (line.hasOption("trace")) {
            defaultProps.setProperty("log4j.rootLogger", "trace,stdout");
        } else if (line.hasOption("debug")) {
            defaultProps.setProperty("log4j.rootLogger", "debug,stdout");
        }

        PropertyConfigurator.configure(defaultProps);

        String training = line.getOptionValue("training");
        File featureFile = new File(training + ".iob2.feat");
        File exampleFile = new File(training);
        File libsvmFile = new File(training + ".iob2.svm");
        File labelFile = new File(training + ".iob2.label");

        File gazetteerFile = new File(line.getOptionValue("gazetteer"));
        new RoleTrainingSetToLibSvm(featureFile, exampleFile, libsvmFile, labelFile, gazetteerFile);
    } catch (ParseException e) {
        // oops, something went wrong
        System.out.println("Parsing failed: " + e.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(400,
                "java -Dfile.encoding=UTF-8 -cp dist/dirha.jar org.fbk.cit.hlt.dirha.RoleTrainingSetToLibSvm",
                "\n", options, "\n", true);
    }
}

From source file:org.fcrepo.modeshape.ModeshapeServer.java

@SuppressWarnings("static-access")
private static Options createOptions() {
    final Options ops = new Options();
    ops.addOption(OptionBuilder.withArgName("num-actions")
            .withDescription("The number of actions performed. [default=1]").withLongOpt("num-actions").hasArg()
            .create('n'));
    ops.addOption(OptionBuilder.withArgName("size").withDescription(
            "The size of the individual binaries used. Sizes with a k,m,g or t postfix will be interpreted as kilo-, mega-, giga- and terabyte [default=1024]")
            .withLongOpt("size").hasArg().create('s'));
    ops.addOption(OptionBuilder.withArgName("num-threads")
            .withDescription("The number of threads used for performing all actions. [default=1]")
            .withLongOpt("num-threads").hasArg().create('t'));
    ops.addOption(OptionBuilder.withArgName("log")
            .withDescription("The log file to which the durations will get written. [default=durations.log]")
            .withLongOpt("log").hasArg().create('l'));
    ops.addOption(OptionBuilder.withDescription("Enable the running the benchmark on this node")
            .withLongOpt("bench").create('b'));
    ops.addOption("h", "help", false, "print the help screen");
    return ops;/* w  ww  .  j  av  a 2 s .  c o m*/
}

From source file:org.geoint.geoserver.configuration.manager.GeoserverConfigCli.java

public static Options getOptions() {
    Option debug_option = OptionBuilder.withDescription("sets logger to all").create("debug");
    Option userName_option = OptionBuilder.withArgName("username").hasArg().isRequired(true)
            .withDescription("(required) domain username").create(OPTION_U);
    Option password_option = OptionBuilder.withArgName("password").isRequired(true).hasArg()
            .withDescription("(required) domain Password").create(OPTION_P);
    Option sourceServer_option = OptionBuilder.withArgName("sourceServer").hasArg()
            .withDescription("The source server URL").create(OPTION_S);
    Option zipLocation_option = OptionBuilder.withArgName("ziplocation").hasArg().isRequired(true)
            .withDescription(//from  w w  w .j  a  v  a 2  s .  co m
                    "(required) the path to the ZIP file. This can be where you want it, or the source for distribution")
            .create(OPTION_Z);
    Option collect_option = OptionBuilder.withArgName(OPTION_COLLECT)
            .withDescription("Collect configuration from server").create(OPTION_COLLECT);
    Option distribute_option = OptionBuilder.withArgName(OPTION_DISTRIBUTE)
            .withDescription("distribute configuration to other geoserver instances").create(OPTION_DISTRIBUTE);
    Option collectanddistribute_option = OptionBuilder.withArgName("collectanddistribute_option")
            .withDescription("collect and distribute configuration to other geoserver instances")
            .create(OPTION_COLLECTANDDISTRIBUTE);
    Option destinationServers_option = OptionBuilder.hasArgs(12)
            .withDescription("a list of destination server URLs comma separated").withValueSeparator(',')
            .create(OPTION_D);
    Option help_option = OptionBuilder.withDescription("prints help").create(OPTION_HELP);

    Options options = new Options();

    options.addOption(debug_option);
    options.addOption(userName_option);
    options.addOption(password_option);
    options.addOption(sourceServer_option);
    options.addOption(zipLocation_option);
    options.addOption(collect_option);
    options.addOption(distribute_option);
    options.addOption(collectanddistribute_option);
    options.addOption(destinationServers_option);
    options.addOption(help_option);

    return options;
}

From source file:org.geoserver.csv2geofence.Cvs2Xml.java

protected static Options createCLIOptions() throws IllegalArgumentException {
    // create Options object
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("the XML configuration file")
            .isRequired().withLongOpt("configfile").create(CLI_CONFIGFILE_CHAR));
    options.addOption(/*  w w  w  . ja  v a2s .c o  m*/
            OptionBuilder.withArgName("file").hasArgs().withDescription("the CSV user/groups file (0 or more)")
                    .withLongOpt("userFile").create(CLI_USERFILE_CHAR));
    options.addOption(
            OptionBuilder.withArgName("file").hasArgs().withDescription("the CSV groups/rules file (0 or more)")
                    .withLongOpt("ruleFile").create(CLI_RULEFILE_CHAR));
    options.addOption(
            OptionBuilder.withArgName("file").hasArgs().withDescription("the output XML GeoFence command")
                    .withLongOpt("output").create(CLI_OUTPUTFILE_CHAR));
    options.addOption(OptionBuilder.withDescription("Send commands to GeoFence").withLongOpt("send")
            .create(CLI_SEND_CHAR));
    //        options.addOption(OptionBuilder
    //                .withDescription("Create groups if they don't exist")
    ////                .withLongOpt("send")
    //                .create(CLI_ALIGNGROUPS_LONG));
    options.addOption(OptionBuilder.withDescription("Delete obsolete rules").withLongOpt(CLI_DELETERULES_LONG)
            .create(CLI_DELETERULES_CHAR));
    return options;
}

From source file:org.glite.security.voms.admin.persistence.tools.AuditLogCtl.java

@SuppressWarnings("static-access")
private CommandLine parseArgs(String[] args) throws ParseException {

    Option help = OptionBuilder.withDescription("prints help").create("help");

    Option vo = OptionBuilder.withArgName("voname").hasArg().withDescription("Act on VO <voname>").create("vo");

    Option fromTime = OptionBuilder.withArgName("time").hasArg()
            .withDescription(/*  w w w .  j a  v  a  2s  .  c  o  m*/
                    "Include records starting from this <time>. Time format is 'yyyy-MM-ddTHH:mm:ss.S'")
            .create("fromTime");

    Option toTime = OptionBuilder.withArgName("time").hasArg()
            .withDescription("Include records to this <time>. Time format is 'yyyy-MM-ddTHH:mm:ss.S'")
            .create("toTime");

    Option type = OptionBuilder.withArgName("eventType").hasArg()
            .withDescription("Include records matching <eventType>").create("eventType");

    Option principal = OptionBuilder.withArgName("principal").hasArg()
            .withDescription("Include records matching <principal>").create("principal");

    Option first = OptionBuilder.withArgName("recordNumber").hasArg()
            .withDescription("Start from <recordNumber> record").create("first");

    Option maxResults = OptionBuilder.withArgName("maxResults").hasArg()
            .withDescription("Return at most <maxResults> records").create("maxResults");

    Option id = OptionBuilder.withArgName("recordId").hasArg().withDescription("Operate on record <recordId>")
            .create("id");

    options = new Options();
    options.addOption(help);
    options.addOption(vo);
    options.addOption(fromTime);
    options.addOption(toTime);
    options.addOption(type);
    options.addOption(principal);
    options.addOption(first);
    options.addOption(maxResults);
    options.addOption(id);

    CommandLineParser parser = new PosixParser();
    return parser.parse(options, args);

}

From source file:org.goobi.eadmgr.Cli.java

@Override
@SuppressWarnings("AccessStaticViaInstance") // workaround for screwed OptionBuilder API
public void initOptions() {
    options = new Options();

    // mutually exclusive main commands
    OptionGroup mainCommands = new OptionGroup();
    mainCommands.addOption(new Option("h", "help", false, "Print this usage information"));
    mainCommands.addOption(//from  ww w. j  a  va  2 s.  co m
            new Option("l", "list-folder-ids", false, "List all folder IDs available for process creation."));
    mainCommands.addOption(new Option("c", "create-process", true,
            "Extracted data for given folder ID as process creation message to configured ActiveMQ server."));
    options.addOptionGroup(mainCommands);

    // additional switches
    options.addOption(OptionBuilder.withLongOpt("validate").withDescription(
            "Validate XML structure of the EAD document. Exits with error code 1 if validation fails. Can be used without other commands for just validating files.")
            .create());
    options.addOption(OptionBuilder.withLongOpt("dry-run")
            .withDescription("Print folder information instead of sending it.").create());
    options.addOption("v", "verbose", false, "Be verbose about what is going on.");
    options.addOption("u", "url", true,
            MessageFormat.format("ActiveMQ Broker URL. If not given the broker is contacted at \"{0}\".\n"
                    + "Note that using the failover protocol will block the program forever if the ActiveMQ host is not reachable unless you specify the \"timeout\" parameter in the URL. See {1} for more information.",
                    DEFAULT_BROKER_URL, ACTIVEMQ_CONFIGURING_URL));
    options.addOption("q", "queue", true, MessageFormat.format(
            "ActiveMQ Subject Queue. If not given messages get enqueue at \"{0}\".", DEFAULT_SUBJECT_QUEUE));
    options.addOption(OptionBuilder.withLongOpt("topic-queue")
            .withDescription(MessageFormat.format(
                    "ActiveMQ result topic Queue. If not given wait for result message posting at \"{0}\".",
                    DEFAULT_RESULT_TOPIC))
            .hasArg().create());
    options.addOption("t", "template", true, MessageFormat
            .format("Goobi Process Template name. If not given \"{0}\" is used.", DEFAULT_PROCESS_TEMPLATE));
    options.addOption("d", "doctype", true,
            MessageFormat.format("Goobi Doctype name. If not given \"{0}\" is used.", DEFAULT_DOCTYPE));
    options.addOption(OptionBuilder.withLongOpt("use-folder-id").withDescription(
            "Use folder ID when generating ActiveMQ Message IDs. If not given a random 128 bit universally unique identifier (UUID) is generated.")
            .create());
    options.addOption(OptionBuilder.withLongOpt("collection")
            .withDescription("Name of a collection to which the newly created process should be assigned.")
            .hasArg().create("C"));
    options.addOption(OptionBuilder
            .withDescription(
                    "User defined option in the form of <key>=<value> to append to the ActiveMQ message.")
            .hasArgs().create("O"));
    options.addOption("x", "extraction-profile", true, MessageFormat.format(
            "XSLT EAD extraction profile name. Either an absolute pathname or a file that can be found on the classpath. If not given \"{0}\" is used.",
            DEFAULT_EXTRACTION_PROFILE));
}

From source file:org.grouplens.lenskit.eval.cli.EvalCLIOptions.java

@SuppressWarnings({ "static-access", "AccessStaticViaInstance" })
private static Options makeOptions() {
    Options opts = new Options();
    opts.addOption(OptionBuilder.withDescription("print this help").withLongOpt("help").create("h"));
    opts.addOption(OptionBuilder.withDescription("print the LensKit version and exit").withLongOpt("version")
            .create("v"));
    opts.addOption(OptionBuilder.withDescription("force eval tasks to run").withLongOpt("force").create("F"));
    opts.addOption(OptionBuilder.withDescription("number of threads to use").hasOptionalArg().withArgName("N")
            .withLongOpt("thread-count").create("j"));
    opts.addOption(OptionBuilder.withDescription("specify the eval configuration script").hasArg()
            .withArgName("FILE").create("f"));
    opts.addOption(OptionBuilder.withDescription("add a JAR or directory to the classpath")
            .withLongOpt("add-to-classpath").hasArg().create("C"));
    opts.addOption(OptionBuilder.withDescription("throw exceptions rather than exiting")
            .withLongOpt("throw-errors").create());
    opts.addOption(OptionBuilder.withDescription("define a property").withArgName("property=value")
            .withValueSeparator().hasArgs(2).create("D"));
    return opts;//w  w w  .j  a va2  s. co m
}

From source file:org.gudy.azureus2.ui.console.commands.AddFind.java

public AddFind() {
    super("add", "a");

    OptionBuilder.withArgName("outputDir");
    OptionBuilder.withLongOpt("output");
    OptionBuilder.hasArg();//  w  w  w . j a  v  a  2 s.  c om
    OptionBuilder.withDescription("override default download directory");
    OptionBuilder.withType(File.class);
    getOptions().addOption(OptionBuilder.create('o'));
    getOptions().addOption("r", "recurse", false, "recurse sub-directories.");
    getOptions().addOption("f", "find", false, "only find files, don't add.");
    getOptions().addOption("h", "help", false, "display help about this command");
    getOptions().addOption("l", "list", false, "list previous find results");
}