Example usage for org.apache.commons.cli Options addOptionGroup

List of usage examples for org.apache.commons.cli Options addOptionGroup

Introduction

In this page you can find the example usage for org.apache.commons.cli Options addOptionGroup.

Prototype

public Options addOptionGroup(OptionGroup group) 

Source Link

Document

Add the specified option group.

Usage

From source file:com.dsf.dbxtract.cdc.App.java

/**
 * Prepare command line options for CLI.
 * /* w  w  w.j  a va2  s  .  c o m*/
 * @return command line options object
 */
private static Options prepareCmdLineOptions() {

    Options options = new Options();
    // required: --config <file>
    options.addOption(Option.builder().longOpt(PARAM_CONFIG).hasArg().numberOfArgs(1).argName("file")
            .desc("configuration file pathname").required().build());

    // commands:
    OptionGroup commands = new OptionGroup();
    // --list
    commands.addOption(Option.builder().longOpt("list").hasArg(false)
            .desc("list configuration parameters and values").required(false).build());
    // --start
    commands.addOption(Option.builder().longOpt("start").hasArg(false).desc("start dbxtract agent")
            .required(false).build());
    options.addOptionGroup(commands);

    return options;
}

From source file:net.sourceforge.docfetcher.CommandLineHandler.java

@SuppressWarnings("static-access")
private static Options createOptions() {
    Options options = new Options();

    // Windows registry manipulation options
    OptionGroup registryGroup = new OptionGroup();
    registryGroup.addOption(OptionBuilder.withLongOpt(REGISTER_CONTEXTMENU)
            .withDescription("add search entry to Windows explorer contextmenu").create());
    registryGroup.addOption(OptionBuilder.withLongOpt(UNREGISTER_CONTEXTMENU)
            .withDescription("remove search entry from Windows explorer contextmenu").create());
    options.addOptionGroup(registryGroup);

    // Text extraction options
    OptionGroup extractGroup = new OptionGroup();
    extractGroup.addOption(OptionBuilder.withLongOpt(EXTRACT)
            .withDescription("extract text from documents to textfile").hasOptionalArgs().create());
    extractGroup.addOption(OptionBuilder.withLongOpt(EXTRACT_DIR)
            .withDescription("extract text from documents to directory").hasOptionalArgs().create());
    options.addOptionGroup(extractGroup);

    // Inclusion and exclusion filter options
    options.addOption(/*from w  ww. ja va2  s.c  o  m*/
            OptionBuilder.withLongOpt(INCLUDE).withDescription("regex inclusion filter for text extraction")
                    .hasArg().withArgName(REGEX).create());
    options.addOption(
            OptionBuilder.withLongOpt(EXCLUDE).withDescription("regex exclusion filter for text extraction")
                    .hasArg().withArgName(REGEX).create());

    // Version info and help options
    options.addOption("h", "help", false, "print this help and exit");
    options.addOption("v", "version", false, "print version number and exit");

    return options;
}

From source file:com.sindicetech.siren.demo.loader.Loader.java

private static Options buildOptions() {
    Options options = new Options();
    // input file name and help are exclusive
    OptionGroup fileHelpGroup = new OptionGroup();
    fileHelpGroup.setRequired(true);// w w  w.  j a  v a 2 s  .com
    fileHelpGroup
            .addOption(OptionBuilder.hasArgs(1).hasOptionalArgs(20).withArgName("file or/and folder name[s]")
                    .withDescription("JSON file[s] or/and director(y|ies) with JSON files (max 20)")
                    .withLongOpt(INPUT_FILE_OPT_LONG).isRequired().create(INPUT_FILE_OPT));

    fileHelpGroup.addOption(OptionBuilder.withDescription("prints help and exits").create(HELP_OPT));
    options.addOptionGroup(fileHelpGroup);
    options.addOption(OptionBuilder.hasArgs(1).withArgName("Solr URL")
            .withDescription("Solr URL (default=" + DEFAULT_SOLR_URL + ")").withLongOpt(URL_OPT_LONG)
            .isRequired(false).create(URL_OPT));

    //    options.addOption(OptionBuilder
    //        .hasArgs(1)
    //        .withArgName("batch size")
    //        .withDescription(
    //            "number of documents sent to Solr in one request, max " + MAX_BATCH_SIZE + " (default="
    //                + DEFAULT_BATCH_SIZE + ")").withLongOpt(BATCH_OPT_LONG).isRequired(false)
    //        .create(BATCH_OPT));

    options.addOption(OptionBuilder
            .withDescription("load all files in directories, not only files with JSON file extension")
            .withLongOpt(NO_EXT_CHECK_OPT_LONG).isRequired(false).create(NO_EXT_CHECK_OPT));
    options.addOption(
            OptionBuilder.withDescription("JSON file extension (default=" + DEFAULT_JSON_EXTENSION + ")")
                    .withLongOpt(EXT_OPT_LONG).isRequired(false).create(EXT_OPT));
    options.addOption(OptionBuilder.withDescription("commit after each file, (default=false)")
            .withLongOpt(COMMIT_EACH_LONG).isRequired(false).create(COMMIT_EACH_OPT));

    return options;
}

From source file:io.github.eternalbits.compactvd.CompactVD.java

private static Options buildOptions() {
    Options options = new Options();
    OptionGroup source = new OptionGroup();
    source.addOption(Option.builder("i").longOpt("inplace").desc("compact <src> image file in place").hasArgs()
            .argName("src").build());
    source.addOption(Option.builder("c").longOpt("copy").desc("copy <src> to a new, optimized image").hasArgs()
            .argName("src").build());
    source.addOption(Option.builder("d").longOpt("dump").desc("print <src> disk image details").hasArgs()
            .argName("src").build());
    source.setRequired(true);/*from w  w  w .ja  v  a  2  s .  c  om*/
    options.addOptionGroup(source);
    options.addOptionGroup(new OptionGroup()
            .addOption(Option.builder("u").longOpt("drop-unused")
                    .desc("drop space not in use by system and files").build())
            .addOption(Option.builder("U").longOpt("keep-unused")
                    .desc("keep space not in use by system and files").build()));
    options.addOptionGroup(new OptionGroup()
            .addOption(Option.builder("z").longOpt("drop-zeroed").desc("drop space filled with zeros").build())
            .addOption(
                    Option.builder("Z").longOpt("keep-zeroed").desc("keep space filled with zeros").build()));
    options.addOption(Option.builder("w").longOpt("write").desc("set <out> as destination file for copy")
            .hasArgs().argName("out").build());
    options.addOption(Option.builder("f").longOpt("format")
            .desc("copy output format: VDI, VMDK, VHD or IMG|RAW").hasArgs().argName("fmt").build());
    options.addOption(Option.builder("o").longOpt("overwrite").desc("overwrite existing file on copy").build());
    options.addOption(Option.builder("v").longOpt("verbose").desc("explain what is being done").build());
    return options;
}

From source file:ape.Main.java

/**
 * This method generates all the options, and stores them in opts
 *//*  w w w  . j  av a 2 s.  co  m*/
public static void createOptions() {
    //System.out.println("creating options ...");
    Options options = new Options();
    options.addOption("h", "help", false, "Displays this help menu");
    options.addOption("V", "version", false, "Displays the version number");
    options.addOption(OptionBuilder.withValueSeparator().withDescription("Turn on verbose mode")
            .withLongOpt("verbose").create("v"));

    // Adds all of the commands in the service loader to an OptionGroup so that they are all mutually exclusive
    OptionGroup apeCommands = new OptionGroup();
    Iterator<ApeCommand> iter = loader.iterator();
    while (iter.hasNext()) {
        ApeCommand ac = iter.next();
        apeCommands.addOption(ac.getOption());
        //System.out.println(ac.getOption());
    }
    options.addOptionGroup(apeCommands);

    // Makes the local and remote commands mutually exclusive
    OptionGroup remoteOrLocal = new OptionGroup();
    remoteOrLocal.addOption(OptionBuilder.withArgName("HostnameList").hasArgs().withValueSeparator()
            .withDescription("Run commands remotely").withLongOpt("remote").create("R"));
    remoteOrLocal.addOption(OptionBuilder.withArgName("Command").withValueSeparator()
            .withDescription("Run commands locally").withLongOpt("local").create("L"));
    options.addOptionGroup(remoteOrLocal);

    opts = options;
}

From source file:com.cjmcgraw.markupvalidator.args.CLIArgumentParser.java

private Options configureOptions() {
    Options result = new Options();
    result.addOptionGroup(createTypeGroup());
    result.addOptionGroup(createInputGroup());
    result.addOption(Arguments.VERBOSE.asOption());
    result.addOption(Arguments.TIME.asOption());
    return result;
}

From source file:com.nokia.tools.vct.cli.CommandLineUtils.java

public static void initOptions(Options options) {
    IExtensionRegistry registry = Platform.getExtensionRegistry();

    IExtension[] extensions = registry.getExtensionPoint(EXTENSION_NAMESPACE).getExtensions();
    for (IExtension extension : extensions) {
        for (IConfigurationElement element : extension.getConfigurationElements()) {
            if (ELEMENT_OPTION.equals(element.getName())) {
                Option option = makeOption(element);
                options.addOption(option);
            } else if (ELEMENT_OPTION_GROUP.equals(element.getName())) {
                OptionGroup optionGroup = new OptionGroup();
                boolean required = Boolean.TRUE.equals(element.getAttribute(OPTION_GROUP_ATTR_REQUIRED));
                optionGroup.setRequired(required);
                for (IConfigurationElement element2 : element.getChildren(ELEMENT_OPTION)) {
                    Option option = makeOption(element2);
                    optionGroup.addOption(option);
                }//from  w  w w .java2 s .co  m
                options.addOptionGroup(optionGroup);
            }
        }
    }
}

From source file:de.thetaphi.forbiddenapis.cli.CliMain.java

public CliMain(String... args) throws ExitException {
    final OptionGroup required = new OptionGroup();
    required.setRequired(true);//from  w w  w  . ja va  2 s.  c  o  m
    required.addOption(dirOpt = Option.builder("d").desc(
            "directory with class files to check for forbidden api usage; this directory is also added to classpath")
            .longOpt("dir").hasArg().argName("directory").build());
    required.addOption(
            versionOpt = Option.builder("V").desc("print product version and exit").longOpt("version").build());
    required.addOption(helpOpt = Option.builder("h").desc("print this help").longOpt("help").build());

    final Options options = new Options();
    options.addOptionGroup(required);
    options.addOption(classpathOpt = Option.builder("c")
            .desc("class search path of directories and zip/jar files").longOpt("classpath").hasArgs()
            .valueSeparator(File.pathSeparatorChar).argName("path").build());
    options.addOption(includesOpt = Option.builder("i").desc(
            "ANT-style pattern to select class files (separated by commas or option can be given multiple times, defaults to '**/*.class')")
            .longOpt("includes").hasArgs().valueSeparator(',').argName("pattern").build());
    options.addOption(excludesOpt = Option.builder("e").desc(
            "ANT-style pattern to exclude some files from checks (separated by commas or option can be given multiple times)")
            .longOpt("excludes").hasArgs().valueSeparator(',').argName("pattern").build());
    options.addOption(signaturesfileOpt = Option.builder("f")
            .desc("path to a file containing signatures (option can be given multiple times)")
            .longOpt("signaturesfile").hasArg().argName("file").build());
    options.addOption(bundledsignaturesOpt = Option.builder("b").desc(
            "name of a bundled signatures definition (separated by commas or option can be given multiple times)")
            .longOpt("bundledsignatures").hasArgs().valueSeparator(',').argName("name").build());
    options.addOption(suppressannotationsOpt = Option.builder().desc(
            "class name or glob pattern of annotation that suppresses error reporting in classes/methods/fields (separated by commas or option can be given multiple times)")
            .longOpt("suppressannotation").hasArgs().valueSeparator(',').argName("classname").build());
    options.addOption(internalruntimeforbiddenOpt = Option.builder().desc(String.format(Locale.ENGLISH,
            "DEPRECATED: forbids calls to non-portable runtime APIs; use bundled signatures '%s' instead",
            BS_JDK_NONPORTABLE)).longOpt("internalruntimeforbidden").build());
    options.addOption(allowmissingclassesOpt = Option.builder()
            .desc("don't fail if a referenced class is missing on classpath").longOpt("allowmissingclasses")
            .build());
    options.addOption(allowunresolvablesignaturesOpt = Option.builder()
            .desc("don't fail if a signature is not resolving").longOpt("allowunresolvablesignatures").build());

    try {
        this.cmd = new DefaultParser().parse(options, args);
        if (cmd.hasOption(helpOpt.getLongOpt())) {
            printHelp(options);
            throw new ExitException(EXIT_SUCCESS);
        }
        if (cmd.hasOption(versionOpt.getLongOpt())) {
            printVersion();
            throw new ExitException(EXIT_SUCCESS);
        }
    } catch (org.apache.commons.cli.ParseException pe) {
        printHelp(options);
        throw new ExitException(EXIT_ERR_CMDLINE);
    }
}

From source file:com.paxxis.cornerstone.messaging.service.shell.ServiceShell.java

private Options initialize(String[] args) {
    OptionGroup group = new OptionGroup();

    Option helpOpt = new Option(null, "help", false, "this message");
    helpOpt.setArgs(2);// w w w .  jav a2s .c  o  m
    helpOpt.setValueSeparator(',');
    group.addOption(helpOpt);

    Option opt = new Option("sh", "shutdown", true, "the service to shut down");
    opt.setArgs(2);
    opt.setValueSeparator(',');
    group.addOption(opt);

    Option updateOpt = new Option(null, "dbupdate", false, "the database update parameters");
    updateOpt.setArgs(3);
    updateOpt.setValueSeparator(',');
    group.addOption(updateOpt);

    Option unbindOpt = new Option(null, "unbind", true,
            "the unbind option to be used ONLY if the service cannot be shut down gracefully");
    unbindOpt.setArgs(2);
    unbindOpt.setValueSeparator(',');
    group.addOption(unbindOpt);
    addOptions(group);

    Options options = new Options();
    options.addOptionGroup(group);
    return options;
}

From source file:net.sourceforge.czt.gnast.Gnast.java

/**
 * Parses the arguments from the command line.
 *
 * @return a configured GnAST builder if parsing was successful;
 *         {@code null} otherwise./*from ww w  . ja  v  a 2s. c  om*/
 * @throws NullPointerException if {@code args} is {@code null}
 */
@SuppressWarnings("static-access")
private static GnastBuilder parseArguments(String[] args) {

    Options argOptions = new Options();

    OptionGroup verboseOptions = new OptionGroup();
    verboseOptions.addOption(OptionBuilder.withLongOpt("verbose")
            .withDescription("Verbose; display verbose debugging messages").create("v"));
    verboseOptions.addOption(OptionBuilder.withLongOpt("vverbose")
            .withDescription("Very verbose; more verbose debugging messages").create("vv"));
    verboseOptions.addOption(OptionBuilder.withLongOpt("vvverbose")
            .withDescription("Very very verbose; even more verbose debugging messages").create("vvv"));
    argOptions.addOptionGroup(verboseOptions);

    argOptions.addOption(OptionBuilder.withLongOpt("finalizers")
            .withDescription("Add AST finalisers. WARNING: ASTs will consume more memory!").create("f"));

    argOptions.addOption(OptionBuilder.withArgName("dir").hasArg().withLongOpt("destination")
            .withDescription("Generated files go into this directory").create("d"));

    argOptions.addOption(OptionBuilder.withArgName("dir1 dir2").hasArgs().withValueSeparator(',')
            .withLongOpt("templates").withDescription("Additional template directories").create("t"));

    argOptions.addOption(OptionBuilder.withArgName("file").hasArg().withLongOpt("mapping")
            .withDescription("XML type mapping properties file").create("m"));

    argOptions.addOption(OptionBuilder.withArgName("dir").hasArg().withLongOpt("source").withDescription(
            "The directory with all ZML schema files. The requested project namespace must be present, as well as all its parents.")
            .create("s"));

    argOptions.addOption(OptionBuilder.withArgName("url").hasArg().withLongOpt("namespace")
            .withDescription("The namespace of the project to be generated.").create("n"));

    // use GNU parser that allows longer option name (e.g. `-vvv`)
    CommandLineParser parser = new GnuParser();
    CommandLine line;
    try {
        // parse the command line arguments
        line = parser.parse(argOptions, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println(exp.getMessage());

        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("gnast", argOptions, true);

        return null;
    }

    Level verbosity = line.hasOption("v") ? Level.INFO
            : (line.hasOption("vv") ? Level.FINE : (line.hasOption("vvv") ? Level.FINER : Level.OFF));

    String[] templates = line.getOptionValues("t");
    List<URL> templateDirs = new ArrayList<URL>();
    for (String path : templates) {
        templateDirs.add(toURL(path));
    }

    return new GnastBuilder().verbosity(verbosity).finalizers(line.hasOption("f"))
            .destination(toFile(line.getOptionValue("d"))).templates(templateDirs)
            .mapping(toURL(line.getOptionValue("m"))).sourceSchemas(schemaDirToURL(line.getOptionValue("s")))
            .namespace(line.getOptionValue("n"));
}