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:daemon.dicomnode.DcmRcv.java

private static CommandLine parse(String[] args) {
    Options opts = new Options();

    OptionBuilder.withArgName("name");
    OptionBuilder.hasArg();//from   w w  w. j  a v  a  2  s  .  c o m
    OptionBuilder.withDescription("set device name, use DCMRCV by default");
    opts.addOption(OptionBuilder.create("device"));

    OptionBuilder.withArgName("NULL|3DES|AES");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("enable TLS connection without, 3DES or AES encryption");
    opts.addOption(OptionBuilder.create("tls"));

    OptionGroup tlsProtocol = new OptionGroup();
    tlsProtocol.addOption(new Option("tls1", "disable the use of SSLv3 and SSLv2 for TLS connections"));
    tlsProtocol.addOption(new Option("ssl3", "disable the use of TLSv1 and SSLv2 for TLS connections"));
    tlsProtocol.addOption(new Option("no_tls1", "disable the use of TLSv1 for TLS connections"));
    tlsProtocol.addOption(new Option("no_ssl3", "disable the use of SSLv3 for TLS connections"));
    tlsProtocol.addOption(new Option("no_ssl2", "disable the use of SSLv2 for TLS connections"));
    opts.addOptionGroup(tlsProtocol);

    opts.addOption("noclientauth", false, "disable client authentification for TLS");

    OptionBuilder.withArgName("file|url");
    OptionBuilder.hasArg();
    OptionBuilder
            .withDescription("file path or URL of P12 or JKS keystore, resource:tls/test_sys_2.p12 by default");
    opts.addOption(OptionBuilder.create("keystore"));

    OptionBuilder.withArgName("password");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("password for keystore file, 'secret' by default");
    opts.addOption(OptionBuilder.create("keystorepw"));

    OptionBuilder.withArgName("password");
    OptionBuilder.hasArg();
    OptionBuilder
            .withDescription("password for accessing the key in the keystore, keystore password by default");
    opts.addOption(OptionBuilder.create("keypw"));

    OptionBuilder.withArgName("file|url");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("file path or URL of JKS truststore, resource:tls/mesa_certs.jks by default");
    opts.addOption(OptionBuilder.create("truststore"));

    OptionBuilder.withArgName("password");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("password for truststore file, 'secret' by default");
    opts.addOption(OptionBuilder.create("truststorepw"));

    OptionBuilder.withArgName("dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("store received objects into files in specified directory <dir>."
            + " Do not store received objects by default.");
    opts.addOption(OptionBuilder.create("dest"));

    OptionBuilder.withArgName("file|url");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("file path or URL of properties for mapping Calling AETs to "
            + "sub-directories of the storage directory specified by "
            + "-dest, to separate the storage location dependend on " + "Calling AETs.");
    opts.addOption(OptionBuilder.create("calling2dir"));

    OptionBuilder.withArgName("file|url");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("file path or URL of properties for mapping Called AETs to "
            + "sub-directories of the storage directory specified by "
            + "-dest, to separate the storage location dependend on " + "Called AETs.");
    opts.addOption(OptionBuilder.create("called2dir"));

    OptionBuilder.withArgName("sub-dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("storage sub-directory used for Calling AETs for which no "
            + " mapping is defined by properties specified by " + "-calling2dir, 'OTHER' by default.");
    opts.addOption(OptionBuilder.create("callingdefdir"));

    OptionBuilder.withArgName("sub-dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("storage sub-directory used for Called AETs for which no "
            + " mapping is defined by properties specified by " + "-called2dir, 'OTHER' by default.");
    opts.addOption(OptionBuilder.create("calleddefdir"));

    OptionBuilder.withArgName("dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("register stored objects in cache journal files in specified directory <dir>."
            + " Do not register stored objects by default.");
    opts.addOption(OptionBuilder.create("journal"));

    OptionBuilder.withArgName("pattern");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("cache journal file path, with "
            + "'yyyy' will be replaced by the current year, "
            + "'MM' by the current month, 'dd' by the current date, "
            + "'HH' by the current hour and 'mm' by the current minute. " + "'yyyy/MM/dd/HH/mm' by default.");
    opts.addOption(OptionBuilder.create("journalfilepath"));

    opts.addOption("defts", false, "accept only default transfer syntax.");
    opts.addOption("bigendian", false, "accept also Explict VR Big Endian transfer syntax.");
    opts.addOption("native", false, "accept only transfer syntax with uncompressed pixel data.");

    OptionGroup scRetrieveAET = new OptionGroup();
    OptionBuilder.withArgName("aet");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Retrieve AE Title included in Storage Commitment "
            + "N-EVENT-REPORT in items of the Referenced SOP Sequence.");
    scRetrieveAET.addOption(OptionBuilder.create("scretraets"));
    OptionBuilder.withArgName("aet");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Retrieve AE Title included in Storage Commitment "
            + "N-EVENT-REPORT outside of the Referenced SOP Sequence.");
    scRetrieveAET.addOption(OptionBuilder.create("scretraet"));
    opts.addOptionGroup(scRetrieveAET);

    opts.addOption("screusefrom", false,
            "attempt to issue the Storage Commitment N-EVENT-REPORT on "
                    + "the same Association on which the N-ACTION operation was "
                    + "performed; use different Association for N-EVENT-REPORT by " + "default.");

    opts.addOption("screuseto", false,
            "attempt to issue the Storage Commitment N-EVENT-REPORT on "
                    + "previous initiated Association to the Storage Commitment SCU; "
                    + "initiate new Association for N-EVENT-REPORT by default.");

    OptionBuilder.withArgName("port");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("port of Storage Commitment SCU to connect to issue "
            + "N-EVENT-REPORT on different Association; 104 by default.");
    opts.addOption(OptionBuilder.create("scport"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder
            .withDescription("delay in ms for N-EVENT-REPORT-RQ to Storage Commitment SCU, " + "1s by default");
    opts.addOption(OptionBuilder.create("scdelay"));

    OptionBuilder.withArgName("retry");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "number of retries to issue N-EVENT-REPORT-RQ to Storage " + "Commitment SCU, 0 by default");
    opts.addOption(OptionBuilder.create("scretry"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("interval im ms between retries to issue N-EVENT-REPORT-RQ to"
            + "Storage Commitment SCU, 60s by default");
    opts.addOption(OptionBuilder.create("scretryperiod"));

    OptionBuilder.withArgName("maxops");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "maximum number of outstanding operations performed " + "asynchronously, unlimited by default.");
    opts.addOption(OptionBuilder.create("async"));

    opts.addOption("pdv1", false, "send only one PDV in one P-Data-TF PDU, "
            + "pack command and data PDV in one P-DATA-TF PDU by default.");
    opts.addOption("tcpdelay", false, "set TCP_NODELAY socket option to false, true by default");

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for TCP connect, no timeout by default");
    opts.addOption(OptionBuilder.create("connectTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving DIMSE-RSP, 10s by default");
    opts.addOption(OptionBuilder.create("rspTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving A-ASSOCIATE-AC, 5s by default");
    opts.addOption(OptionBuilder.create("acceptTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("delay in ms for Socket close after sending A-ABORT, 50ms by default");
    opts.addOption(OptionBuilder.create("soclosedelay"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("delay in ms for DIMSE-RSP; useful for testing asynchronous mode");
    opts.addOption(OptionBuilder.create("rspdelay"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving -ASSOCIATE-RQ, 5s by default");
    opts.addOption(OptionBuilder.create("requestTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving A-RELEASE-RP, 5s by default");
    opts.addOption(OptionBuilder.create("releaseTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("period in ms to check for outstanding DIMSE-RSP, 10s by default");
    opts.addOption(OptionBuilder.create("reaper"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving DIMSE-RQ, 60s by default");
    opts.addOption(OptionBuilder.create("idleTO"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("maximal length in KB of received P-DATA-TF PDUs, 16KB by default");
    opts.addOption(OptionBuilder.create("rcvpdulen"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("maximal length in KB of sent P-DATA-TF PDUs, 16KB by default");
    opts.addOption(OptionBuilder.create("sndpdulen"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("set SO_RCVBUF socket option to specified value in KB");
    opts.addOption(OptionBuilder.create("sorcvbuf"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("set SO_SNDBUF socket option to specified value in KB");
    opts.addOption(OptionBuilder.create("sosndbuf"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("minimal buffer size to write received object to file, 1KB by default");
    opts.addOption(OptionBuilder.create("bufsize"));

    opts.addOption("h", "help", false, "print this message");
    opts.addOption("V", "version", false, "print the version information and exit");
    CommandLine cl = null;
    try {
        cl = new GnuParser().parse(opts, args);
    } catch (ParseException e) {
        exit("dcmrcv: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption("V")) {
        Package p = DcmRcv.class.getPackage();
        System.out.println("dcmrcv v" + p.getImplementationVersion());
        System.exit(0);
    }
    if (cl.hasOption("h") || cl.getArgList().size() == 0) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE);
        System.exit(0);
    }
    return cl;
}

From source file:com.databasepreservation.cli.CLI.java

/**
 * Obtains the arguments needed to create new import and export modules
 *
 * @param factoriesPair/* w  ww.java  2  s.  c  o m*/
 *          A pair of DatabaseModuleFactory objects containing the selected
 *          import and export module factories
 * @param args
 *          The command line arguments
 * @return A DatabaseModuleFactoriesArguments containing the arguments to
 *         create the import and export modules
 * @throws ParseException
 *           If the arguments could not be parsed or are invalid
 */
private DatabaseModuleFactoriesArguments getModuleArguments(DatabaseModuleFactoriesPair factoriesPair,
        List<String> args) throws ParseException, OperationNotSupportedException {
    DatabaseModuleFactory importModuleFactory = factoriesPair.getImportModuleFactory();
    DatabaseModuleFactory exportModuleFactory = factoriesPair.getExportModuleFactory();

    // get appropriate command line options
    CommandLineParser commandLineParser = new DefaultParser();
    CommandLine commandLine;
    Options options = new Options();

    HashMap<String, Parameter> mapOptionToParameter = new HashMap<String, Parameter>();

    for (Parameter parameter : importModuleFactory.getImportModuleParameters().getParameters()) {
        Option option = parameter.toOption("i", "import");
        options.addOption(option);
        mapOptionToParameter.put(getUniqueOptionIdentifier(option), parameter);
    }
    for (ParameterGroup parameterGroup : importModuleFactory.getImportModuleParameters().getGroups()) {
        OptionGroup optionGroup = parameterGroup.toOptionGroup("i", "import");
        options.addOptionGroup(optionGroup);

        for (Parameter parameter : parameterGroup.getParameters()) {
            mapOptionToParameter.put(getUniqueOptionIdentifier(parameter.toOption("i", "import")), parameter);
        }
    }
    for (Parameter parameter : exportModuleFactory.getExportModuleParameters().getParameters()) {
        Option option = parameter.toOption("e", "export");
        options.addOption(option);
        mapOptionToParameter.put(getUniqueOptionIdentifier(option), parameter);
    }
    for (ParameterGroup parameterGroup : exportModuleFactory.getExportModuleParameters().getGroups()) {
        OptionGroup optionGroup = parameterGroup.toOptionGroup("e", "export");
        options.addOptionGroup(optionGroup);

        for (Parameter parameter : parameterGroup.getParameters()) {
            mapOptionToParameter.put(getUniqueOptionIdentifier(parameter.toOption("e", "export")), parameter);
        }
    }

    Option importOption = Option.builder("i").longOpt("import").hasArg().optionalArg(false).build();
    Option exportOption = Option.builder("e").longOpt("export").hasArg().optionalArg(false).build();
    Option pluginOption = Option.builder("p").longOpt("plugin").hasArg().optionalArg(false).build();
    options.addOption(importOption);
    options.addOption(exportOption);
    options.addOption(pluginOption);

    // new HelpFormatter().printHelp(80, "dbptk", "\nModule Options:", options,
    // null, true);

    // parse the command line arguments with those options
    try {
        commandLine = commandLineParser.parse(options, args.toArray(new String[] {}), false);
        if (!commandLine.getArgList().isEmpty()) {
            throw new ParseException("Unrecognized option: " + commandLine.getArgList().get(0));
        }
    } catch (MissingOptionException e) {
        // use long names instead of short names in the error message
        List<String> missingShort = e.getMissingOptions();
        List<String> missingLong = new ArrayList<String>();
        for (String shortOption : missingShort) {
            missingLong.add(options.getOption(shortOption).getLongOpt());
        }
        LOGGER.debug("MissingOptionException (the original, unmodified exception)", e);
        throw new MissingOptionException(missingLong);
    }

    // create arguments to pass to factory
    HashMap<Parameter, String> importModuleArguments = new HashMap<Parameter, String>();
    HashMap<Parameter, String> exportModuleArguments = new HashMap<Parameter, String>();
    for (Option option : commandLine.getOptions()) {
        Parameter p = mapOptionToParameter.get(getUniqueOptionIdentifier(option));
        if (p != null) {
            if (isImportModuleOption(option)) {
                if (p.hasArgument()) {
                    importModuleArguments.put(p, option.getValue(p.valueIfNotSet()));
                } else {
                    importModuleArguments.put(p, p.valueIfSet());
                }
            } else if (isExportModuleOption(option)) {
                if (p.hasArgument()) {
                    exportModuleArguments.put(p, option.getValue(p.valueIfNotSet()));
                } else {
                    exportModuleArguments.put(p, p.valueIfSet());
                }
            } else {
                throw new ParseException("Unexpected parse exception occurred.");
            }
        }
    }
    return new DatabaseModuleFactoriesArguments(importModuleArguments, exportModuleArguments);
}

From source file:com.archivas.clienttools.arcmover.cli.ArcProfileMgr.java

@SuppressWarnings({ "static-access" })
public Options getOptions() {
    if (cliOptions == null) {
        Options options = new Options();

        OptionGroup operations = new OptionGroup();

        // *** Adding a new option needs to be added to the cliOrder list
        operations.addOption(OptionBuilder.withDescription("Displays this help text (the default behavior).")
                .withLongOpt("help").create("h"));

        operations.addOption(OptionBuilder.hasOptionalArg().withArgName("profile_name").withDescription(
                "Lists information about the specified namespace profile.  If <profile_name> is omitted, lists information about all namespace profiles.")
                .withLongOpt("list").create("l"));
        operations.addOption(OptionBuilder.hasArg().withArgName("profile_name")
                .withDescription("Deletes the specified namespace profile.").withLongOpt("delete").create("d"));
        operations.addOption(OptionBuilder.hasArg().withArgName("profile_name")
                .withDescription("Creates a namespace profile with the specified name.").withLongOpt("create")
                .create("c"));

        options.addOptionGroup(operations);

        // List the valid profile types dynamically
        String profileTypesToString = "Type of namespace for which you are creating the namespace profile: ";
        for (ProfileType type : ProfileType.values()) {
            if (type != ProfileType.FILESYSTEM) { // Filesystem is already createdcd
                profileTypesToString += (type.toString() + " | ");
            }//ww w  .  j  a va2  s  .  c  o  m
        }
        profileTypesToString = profileTypesToString.substring(0, profileTypesToString.length() - 3);

        options.addOption(OptionBuilder.withArgName("profile_type").hasArg()
                .withDescription(profileTypesToString).withLongOpt("type").create());
        options.addOption(OptionBuilder.withArgName("tenant_name").hasArg().withDescription(
                "Name of the tenant that owns the namespace for which you are creating the namespace profile.")
                .withLongOpt("tenant").create());
        options.addOption(OptionBuilder.withArgName("namespace_name").hasArg()
                .withDescription("Name of the namespace for which you are creating the namespace profile.")
                .withLongOpt("namespace").create());
        options.addOption(OptionBuilder.withArgName("username").hasArg()
                .withDescription("Username of the data access account to use for namespace access.")
                .withLongOpt("username").create());
        options.addOption(OptionBuilder.withArgName("password").hasArg()
                .withDescription("Password of the data access account to use for namespace access.")
                .withLongOpt("password").create());
        options.addOption(OptionBuilder.withArgName("hostname").hasArg()
                .withDescription("The fully qualified domain name of the HCP system.").withLongOpt("hostname")
                .create());
        options.addOption(
                OptionBuilder.withDescription("Tells HCP-DM to use SSL when communicating with the HCP system.")
                        .withLongOpt("ssl").create());
        options.addOption(OptionBuilder.withDescription(
                "Tells HCP-DM to check whether custom metadata XML is well-formed prior to communicating with the HCP system.")
                .withLongOpt("check-cm").create());
        options.addOption(OptionBuilder
                .withDescription("Log into namespace anonymously.  Only valid with HCP 5.0 or later profile.")
                .withLongOpt("anon").create());
        options.addOption(OptionBuilder.withDescription(
                "Does not test if the namespace configuration provided can access HCP while creating the profile.")
                .withLongOpt("notest").create());
        options.addOption(OptionBuilder.withArgName("address1[,address2]...").hasArg().withDescription(
                "Comma-separated list of one or more IP addresses to use to connect to the HCP system.  If omitted, HCP-DM uses the hostname.")
                .withLongOpt("ips").create());
        if (ALLOW_PORT) {
            options.addOption(OptionBuilder.withArgName("port").hasArg()
                    .withDescription("Port to connect to HCP on").withLongOpt("port").create());
        }

        cliOptions = options;
    }
    return cliOptions;
}

From source file:de.bmw.yamaica.common.console.CommandExecuter.java

private List<ConsoleConfiguration> getParsedExtensionPointConfigurations() {
    List<ConsoleConfiguration> configurations = new ArrayList<ConsoleConfiguration>();

    // Parse extension point information
    IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
    IExtensionPoint commandsExtensionPoint = extensionRegistry.getExtensionPoint(COMMANDS_EXTENSION_POINT_ID);

    if (null != commandsExtensionPoint) {
        Map<String, IConfigurationElement> referenceableOptionConfigurations = parseExtensionPoint(
                extensionRegistry.getExtensionPoint(OPTIONS_EXTENSION_POINT_ID), OPTION_ID_ATTRIBUTE_NAME);
        Map<String, IConfigurationElement> referenceableOptionGroupConfigurations = parseExtensionPoint(
                extensionRegistry.getExtensionPoint(OPTION_GROUPS_EXTENSION_POINT_ID),
                OPTION_GROUP_ID_ATTRIBUTE_NAME);

        for (IConfigurationElement commandConfiguration : commandsExtensionPoint.getConfigurationElements()) {
            String id = commandConfiguration.getAttribute(COMMAND_ID_ATTRIBUTE_NAME);

            try {
                Options options = new Options();

                String name = commandConfiguration.getAttribute(COMMAND_NAME_ATTRIBUTE_NAME);
                String syntax = commandConfiguration.getAttribute(COMMAND_SYNTAX_ATTRIBUTE_NAME);
                String header = null;
                String footer = null;

                for (IConfigurationElement childConfiguration : commandConfiguration.getChildren()) {
                    switch (childConfiguration.getName()) {
                    case OPTIONS_CONFIGURATION_NAME:
                        for (IConfigurationElement optionConfiguration : childConfiguration.getChildren()) {
                            Option option = getOptionByConfiguration(optionConfiguration,
                                    referenceableOptionConfigurations);
                            OptionGroup optionGroup = getOptionGroupByConfiguration(optionConfiguration,
                                    referenceableOptionGroupConfigurations, referenceableOptionConfigurations);

                            if (null != option) {
                                options.addOption(option);
                            }/*from   w w w.  j  a  v a2  s  .  c  o m*/

                            if (null != optionGroup) {
                                options.addOptionGroup(optionGroup);
                            }
                        }
                        break;

                    case HEADER_CONFIGURATION_NAME:
                        header = childConfiguration.getValue();
                        break;

                    case FOOTER_CONFIGURATION_NAME:
                        footer = childConfiguration.getValue();
                        break;
                    }
                }

                if (options.getRequiredOptions().size() < 1) {
                    throw new IllegalArgumentException(String.format(NO_REQUIRED_OPTION_MESSAGE));
                }

                configurations.add(new ConsoleConfiguration(commandConfiguration, options, id, name, syntax,
                        header, footer));
            } catch (Exception exception) {
                String message = String
                        .format(EXTENSION_POINT_PARSING_ERROR_MESSAGE + " " + exception.getMessage(), id);

                log(new IllegalArgumentException(message, exception));
            }
        }
    }

    return configurations;
}

From source file:de.zib.scalaris.Main.java

/**
 * Creates the options the command line should understand.
 * /*  w  w w  . j a  v a2 s.  co  m*/
 * @return the options the program understands
 */
private static Options getOptions() {
    Options options = new Options();
    OptionGroup group = new OptionGroup();

    /* Note: arguments are set to be optional since we implement argument
     * checks on our own (commons.cli is not flexible enough and only
     * checks for the existence of a first argument)
     */

    options.addOption(new Option("h", "help", false, "print this message"));

    options.addOption(new Option("v", "verbose", false, "print verbose information, e.g. the properties read"));

    Option read = new Option("r", "read", true, "read an item");
    read.setArgName("key");
    read.setArgs(1);
    read.setOptionalArg(true);
    group.addOption(read);

    Option write = new Option("w", "write", true, "write an item");
    write.setArgName("key> <value");
    write.setArgs(2);
    write.setOptionalArg(true);
    group.addOption(write);

    Option publish = new Option("p", "publish", true, "publish a new message for the given topic");
    publish.setArgName("topic> <message");
    publish.setArgs(2);
    publish.setOptionalArg(true);
    group.addOption(publish);

    Option subscribe = new Option("s", "subscribe", true, "subscribe to a topic");
    subscribe.setArgName("topic> <url");
    subscribe.setArgs(2);
    subscribe.setOptionalArg(true);
    group.addOption(subscribe);

    Option unsubscribe = new Option("u", "unsubscribe", true, "unsubscribe from a topic");
    unsubscribe.setArgName("topic> <url");
    unsubscribe.setArgs(2);
    unsubscribe.setOptionalArg(true);
    group.addOption(unsubscribe);

    Option getSubscribers = new Option("g", "getsubscribers", true, "get subscribers of a topic");
    getSubscribers.setArgName("topic");
    getSubscribers.setArgs(1);
    getSubscribers.setOptionalArg(true);
    group.addOption(getSubscribers);

    Option delete = new Option("d", "delete", true,
            "delete an item (default timeout: 2000ms)\n"
                    + "WARNING: This function can lead to inconsistent data (e.g. "
                    + "deleted items can re-appear). Also when re-creating an item "
                    + "the version before the delete can re-appear.");
    delete.setArgName("key> <[timeout]");
    delete.setArgs(2);
    delete.setOptionalArg(true);
    group.addOption(delete);

    options.addOption(new Option("b", "minibench", false, "run mini benchmark"));

    options.addOption(new Option("lh", "localhost", false,
            "gets the local host's name as known to Java (for debugging purposes)"));

    options.addOptionGroup(group);

    return options;
}

From source file:de.zib.chordsharp.Main.java

/**
 * creates the options the command line should understand
 * //  w w w. j a v a  2  s  . c om
 * @return the options the program understands
 */
private static Options getOptions() {
    Options options = new Options();
    OptionGroup group = new OptionGroup();

    options.addOption(new Option("help", "print this message"));

    Option read = OptionBuilder.create("read");
    read.setArgName("key");
    read.setArgs(1);
    read.setDescription("read an item");
    //      Option read = OptionBuilder.withArgName("key").hasArg()
    //            .withDescription("read an item").create("read");
    group.addOption(read);

    Option write = OptionBuilder.create("write");
    write.setArgName("params");
    write.setArgs(2);
    write.setDescription("write an item: <key> <value>");
    //      Option write = OptionBuilder.withArgName("params").hasArgs(2)
    //            .withDescription("write an item: <key> <value>")
    //            .create("write");
    group.addOption(write);

    Option publish = OptionBuilder.create("publish");
    publish.setArgName("params");
    publish.setArgs(2);
    publish.setDescription("publish a new message for a topic: <topic> <message>");
    //      Option publish = OptionBuilder.withArgName("params").hasArgs(2)
    //            .withDescription(
    //                  "publish a new message for a topic: <topic> <message>")
    //            .create("publish");
    group.addOption(publish);

    Option subscribe = OptionBuilder.create("subscribe");
    subscribe.setArgName("params");
    subscribe.setArgs(2);
    subscribe.setDescription("subscribe to a topic: <topic> <url>");
    //      Option subscribe = OptionBuilder.withArgName("params").hasArgs(2)
    //            .withDescription("subscribe to a topic: <topic> <url>").create(
    //                  "subscribe");
    group.addOption(subscribe);

    Option unsubscribe = OptionBuilder.create("unsubscribe");
    unsubscribe.setArgName("params");
    unsubscribe.setArgs(2);
    unsubscribe.setDescription("unsubscribe from a topic: <topic> <url>");
    //      Option subscribe = OptionBuilder.withArgName("params").hasArgs(2)
    //            .withDescription("unsubscribe from a topic: <topic> <url>").create(
    //                  "unsubscribe");
    group.addOption(unsubscribe);

    Option getSubscribers = OptionBuilder.create("getsubscribers");
    getSubscribers.setArgName("topic");
    getSubscribers.setArgs(1);
    getSubscribers.setDescription("get subscribers of a topic");
    //      Option getSubscribers = OptionBuilder.withArgName("topic").hasArgs(1)
    //            .withDescription("get subscribers of a topic").create(
    //                  "getsubscribers");
    group.addOption(getSubscribers);

    options.addOption(new Option("minibench", "run mini benchmark"));

    options.addOptionGroup(group);

    return options;
}

From source file:com.emc.vipr.sync.ViPRSync.java

protected static Options mainOptions() {
    Options options = new Options();
    options.addOption(new OptionBuilder().withLongOpt(HELP_OPTION).withDescription(HELP_DESC).create());
    options.addOption(new OptionBuilder().withLongOpt(SPRING_CONFIG_OPTION).withDescription(SPRING_CONFIG_DESC)
            .hasArg().withArgName(SPRING_CONFIG_ARG_NAME).create());
    options.addOption(new OptionBuilder().withLongOpt(QUERY_THREADS_OPTION).withDescription(QUERY_THREADS_DESC)
            .hasArg().withArgName(QUERY_THREADS_ARG_NAME).create());
    options.addOption(new OptionBuilder().withLongOpt(SYNC_THREADS_OPTION).withDescription(SYNC_THREADS_DESC)
            .hasArg().withArgName(SYNC_THREADS_ARG_NAME).create());
    options.addOption(new OptionBuilder().withLongOpt(SOURCE_OPTION).withDescription(SOURCE_DESC).hasArg()
            .withArgName(SOURCE_ARG_NAME).create());
    options.addOption(new OptionBuilder().withLongOpt(TARGET_OPTION).withDescription(TARGET_DESC).hasArg()
            .withArgName(TARGET_ARG_NAME).create());
    options.addOption(new OptionBuilder().withLongOpt(FILTERS_OPTION).withDescription(FILTERS_DESC).hasArg()
            .withArgName(FILTERS_ARG_NAME).create());
    options.addOption(/*from  w  ww  .  ja v a 2  s  .  co m*/
            new OptionBuilder().withLongOpt(NON_RECURSIVE_OPTION).withDescription(NON_RECURSIVE_DESC).create());
    options.addOption(new OptionBuilder().withLongOpt(TIMINGS_OPTION).withDescription(TIMINGS_DESC).create());
    options.addOption(new OptionBuilder().withLongOpt(TIMING_WINDOW_OPTION).withDescription(TIMING_WINDOW_DESC)
            .hasArg().withArgName(TIMING_WINDOW_ARG_NAME).create());
    options.addOption(
            new OptionBuilder().withLongOpt(FORGET_FAILED_OPTION).withDescription(FORGET_FAILED_DESC).create());
    options.addOption(
            new OptionBuilder().withLongOpt(DELETE_SOURCE_OPTION).withDescription(DELETE_SOURCE_DESC).create());

    OptionGroup loggingOpts = new OptionGroup();
    loggingOpts.addOption(new OptionBuilder().withLongOpt(DEBUG_OPTION).withDescription(DEBUG_DESC).create());
    loggingOpts
            .addOption(new OptionBuilder().withLongOpt(VERBOSE_OPTION).withDescription(VERBOSE_DESC).create());
    loggingOpts.addOption(new OptionBuilder().withLongOpt(SILENT_OPTION).withDescription(SILENT_DESC).create());
    loggingOpts.addOption(new OptionBuilder().withLongOpt(QUIET_OPTION).withDescription(QUIET_DESC).create());
    options.addOptionGroup(loggingOpts);

    return options;
}

From source file:net.lldp.checksims.ChecksimsCommandLine.java

/**
 * @param anyRequired Whether any arguments are required
 * @return CLI options used in Checksims
 *///  w w w  .  j av a 2  s.c o m
static Options getOpts(boolean anyRequired) {
    Options opts = new Options();

    Option alg = Option.builder("a").longOpt("algorithm").hasArg().argName("name")
            .desc("algorithm to compare with").build();

    Option token = Option.builder("t").longOpt("token").hasArg().argName("type")
            .desc("tokenization to use for submissions").build();

    Option out = Option.builder("o").longOpt("output").hasArgs().argName("name1[,name2,...]")
            .valueSeparator(',').desc("output format(s) to use, comma-separated if multiple given").build();

    Option ignoreInvalid = Option.builder().longOpt("ignoreInvalid")
            .desc("Do not show the result of submissions that do not parse correctly").build();

    Option file = Option.builder("f").longOpt("file").hasArg().argName("filename")
            .desc("print output to given file").build();

    Option preprocess = Option.builder("p").longOpt("preprocess").hasArgs().argName("name1[,name2,...]")
            .valueSeparator(',').desc("preprocessor(s) to apply, comma-separated if multiple given").build();

    Option jobs = Option.builder("j").longOpt("jobs").hasArg().argName("num").desc("number of threads to use")
            .build();

    Option glob = Option.builder("g").longOpt("glob").hasArg().argName("matchpattern")
            .desc("match pattern to determine files included in submissions").build();

    OptionGroup verbosity = new OptionGroup();
    Option verbose = new Option("v", "verbose", false, "specify verbose output. conflicts with -vv");
    Option doubleVerbose = new Option("vv", "veryverbose", false,
            "specify very verbose output. conflicts with -v");
    verbosity.addOption(verbose);
    verbosity.addOption(doubleVerbose);

    Option help = new Option("h", "help", false, "show usage information");

    Option empty = new Option("e", "empty", false, "retain empty submissions");

    Option common = Option.builder("c").longOpt("common").hasArg().argName("path")
            .desc("directory containing common code which will be removed from all submissions").build();

    Option recursive = new Option("r", "recursive", false,
            "recursively traverse subdirectories to generate submissions");

    Option version = new Option("version", false, "print version of Checksims");

    Option archiveDir = Option.builder("archive").longOpt("archivedir")
            .desc("archive submissions - compared to main submissions but not each other").argName("path")
            .hasArgs().valueSeparator('*').build();

    Option submissionDir = Option.builder("s").longOpt("submissiondir")
            .desc("directory or directories containing submissions to compare - mandatory!").argName("path")
            .hasArgs().valueSeparator('*').build();

    if (anyRequired) {
        submissionDir.setRequired(true);
    }

    opts.addOption(alg);
    opts.addOption(token);
    opts.addOption(out);
    opts.addOption(file);
    opts.addOption(preprocess);
    opts.addOption(jobs);
    opts.addOption(glob);
    opts.addOptionGroup(verbosity);
    opts.addOption(help);
    opts.addOption(empty);
    opts.addOption(common);
    opts.addOption(recursive);
    opts.addOption(version);
    opts.addOption(archiveDir);
    opts.addOption(submissionDir);
    opts.addOption(ignoreInvalid);

    return opts;
}

From source file:com.springrts.springls.CmdLineArgs.java

private static Options createOptions() {

    Configuration defaults = ServerConfiguration.getDefaults();

    Options options = new Options();

    Option help = new Option(null, "help", false, "Print this help message.");
    options.addOption(help);//from  w w w .j av  a 2  s  . c o m

    Option port = new Option("p", "port", true,
            String.format("The main (TCP) port number to host on [1, 65535]." + " The default is %d.",
                    defaults.getInt(ServerConfiguration.PORT)));
    // possible types:
    // * File.class
    // * Number.class
    // * Class.class
    // * Object.class
    // * Url.class
    port.setType(Number.class);
    port.setArgName("port-number");
    options.addOption(port);

    Option statistics = new Option(null, "statistics", false,
            "Whether to create and save statistics to disc on predefined" + " intervals.");
    options.addOption(statistics);

    Option natPort = new Option("n", "nat-port", true,
            String.format(
                    "The (UDP) port number to host the NAT traversal techniques"
                            + " help service on [1, 65535], which lets clients detect their"
                            + " source port, for example when using \"hole punching\"." + " The default is %d.",
                    defaults.getInt(ServerConfiguration.NAT_PORT)));
    port.setType(Number.class);
    natPort.setArgName("NAT-port-number");
    options.addOption(natPort);

    Option logMain = new Option(null, "log-main", false,
            String.format("Whether to log all conversations from channel #main to \"%s\"",
                    Channel.createDefaultActivityLogFilePath("main").getPath()));
    options.addOption(logMain);

    Option lanAdmin = new Option(null, "lan-admin", true,
            String.format(
                    "The LAN mode admin account. Use this account to administer"
                            + " your LAN server. The default is \"%s\", with password \"%s\".",
                    defaults.getString(ServerConfiguration.LAN_ADMIN_USERNAME),
                    defaults.getString(ServerConfiguration.LAN_ADMIN_PASSWORD)));
    lanAdmin.setArgName("username");
    options.addOption(lanAdmin);

    Option loadArgs = new Option(null, "load-args", true,
            "Will read command-line arguments from the specified file."
                    + " You can freely combine actual command-line arguments with"
                    + " the ones from the file. If duplicate args are specified,"
                    + " the last one will prevail.");
    loadArgs.setArgName("filename");
    port.setType(File.class);
    options.addOption(loadArgs);

    Option springVersion = new Option(null, "spring-version", true,
            "Will set the latest Spring version to this string."
                    + " The default is \"*\". This is used to tell clients which"
                    + " version is the latest one, so that they know when to" + " update.");
    springVersion.setArgName("version");
    options.addOption(springVersion);

    Option useStorageDb = new Option(null, "database", false,
            "Use a DB for user accounts and ban entries." + " This disables \"LAN mode\".");
    options.addOption(useStorageDb);

    Option useStorageFile = new Option(null, "file-storage", false,
            "Use the (deprecated) accounts.txt for user accounts." + " This disables \"LAN mode\".");
    options.addOption(useStorageFile);

    OptionGroup storageOG = new OptionGroup();
    storageOG.addOption(useStorageDb);
    storageOG.addOption(useStorageFile);
    options.addOptionGroup(storageOG);

    return options;
}

From source file:mod.org.dcm4che2.tool.DcmQR.java

private static CommandLine parse(String[] args) {
    Options opts = new Options();

    OptionBuilder.withArgName("name");
    OptionBuilder.hasArg();// w w w .j a  v a 2s  .c  o  m
    OptionBuilder.withDescription("set device name, use DCMQR by default");
    opts.addOption(OptionBuilder.create("device"));

    OptionBuilder.withArgName("aet[@host][:port]");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("set AET, local address and listening port of local"
            + "Application Entity, use device name and pick up any valid "
            + "local address to bind the socket by default");
    opts.addOption(OptionBuilder.create("L"));

    OptionBuilder.withArgName("username");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "enable User Identity Negotiation with specified username and " + " optional passcode");
    opts.addOption(OptionBuilder.create("username"));

    OptionBuilder.withArgName("passcode");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "optional passcode for User Identity Negotiation, " + "only effective with option -username");
    opts.addOption(OptionBuilder.create("passcode"));

    opts.addOption("uidnegrsp", false,
            "request positive User Identity Negotation response, " + "only effective with option -username");

    OptionBuilder.withArgName("NULL|3DES|AES");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("enable TLS connection without, 3DES or AES encryption");
    opts.addOption(OptionBuilder.create("tls"));

    OptionGroup tlsProtocol = new OptionGroup();
    tlsProtocol.addOption(new Option("tls1", "disable the use of SSLv3 and SSLv2 for TLS connections"));
    tlsProtocol.addOption(new Option("ssl3", "disable the use of TLSv1 and SSLv2 for TLS connections"));
    tlsProtocol.addOption(new Option("no_tls1", "disable the use of TLSv1 for TLS connections"));
    tlsProtocol.addOption(new Option("no_ssl3", "disable the use of SSLv3 for TLS connections"));
    tlsProtocol.addOption(new Option("no_ssl2", "disable the use of SSLv2 for TLS connections"));
    opts.addOptionGroup(tlsProtocol);

    opts.addOption("noclientauth", false, "disable client authentification for TLS");

    OptionBuilder.withArgName("file|url");
    OptionBuilder.hasArg();
    OptionBuilder
            .withDescription("file path or URL of P12 or JKS keystore, resource:tls/test_sys_1.p12 by default");
    opts.addOption(OptionBuilder.create("keystore"));

    OptionBuilder.withArgName("password");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("password for keystore file, 'secret' by default");
    opts.addOption(OptionBuilder.create("keystorepw"));

    OptionBuilder.withArgName("password");
    OptionBuilder.hasArg();
    OptionBuilder
            .withDescription("password for accessing the key in the keystore, keystore password by default");
    opts.addOption(OptionBuilder.create("keypw"));

    OptionBuilder.withArgName("file|url");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("file path or URL of JKS truststore, resource:tls/mesa_certs.jks by default");
    opts.addOption(OptionBuilder.create("truststore"));

    OptionBuilder.withArgName("password");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("password for truststore file, 'secret' by default");
    opts.addOption(OptionBuilder.create("truststorepw"));

    OptionBuilder.withArgName("aet");
    OptionBuilder.hasArg();
    OptionBuilder
            .withDescription("retrieve instances of matching entities by C-MOVE to specified destination.");
    opts.addOption(OptionBuilder.create("cmove"));

    opts.addOption("nocfind", false,
            "retrieve instances without previous query - unique keys must be specified by -q options");

    opts.addOption("cget", false, "retrieve instances of matching entities by C-GET.");

    OptionBuilder.withArgName("cuid[:ts]");
    OptionBuilder.hasArgs();
    OptionBuilder.withDescription("negotiate support of specified Storage SOP Class and Transfer "
            + "Syntaxes. The Storage SOP Class may be specified by its UID "
            + "or by one of following key words:\n" + "CR  - Computed Radiography Image Storage\n"
            + "CT  - CT Image Storage\n" + "MR  - MRImageStorage\n" + "US  - Ultrasound Image Storage\n"
            + "NM  - Nuclear Medicine Image Storage\n" + "PET - PET Image Storage\n"
            + "SC  - Secondary Capture Image Storage\n" + "XA  - XRay Angiographic Image Storage\n"
            + "XRF - XRay Radiofluoroscopic Image Storage\n"
            + "DX  - Digital X-Ray Image Storage for Presentation\n"
            + "MG  - Digital Mammography X-Ray Image Storage for Presentation\n"
            + "PR  - Grayscale Softcopy Presentation State Storage\n"
            + "KO  - Key Object Selection Document Storage\n"
            + "SR  - Basic Text Structured Report Document Storage\n"
            + "The Transfer Syntaxes may be specified by a comma "
            + "separated list of UIDs or by one of following key " + "words:\n"
            + "IVRLE - offer only Implicit VR Little Endian " + "Transfer Syntax\n"
            + "LE - offer Explicit and Implicit VR Little Endian " + "Transfer Syntax\n"
            + "BE - offer Explicit VR Big Endian Transfer Syntax\n"
            + "DEFL - offer Deflated Explicit VR Little " + "Endian Transfer Syntax\n"
            + "JPLL - offer JEPG Loss Less Transfer Syntaxes\n" + "JPLY - offer JEPG Lossy Transfer Syntaxes\n"
            + "MPEG2 - offer MPEG2 Transfer Syntax\n" + "NOPX - offer No Pixel Data Transfer Syntax\n"
            + "NOPXD - offer No Pixel Data Deflate Transfer Syntax\n"
            + "If only the Storage SOP Class is specified, all "
            + "Transfer Syntaxes listed above except No Pixel Data "
            + "and No Pixel Data Delflate Transfer Syntax are " + "offered.");
    opts.addOption(OptionBuilder.create("cstore"));

    OptionBuilder.withArgName("dir");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("store received objects into files in specified directory <dir>."
            + " Do not store received objects by default.");
    opts.addOption(OptionBuilder.create("cstoredest"));

    opts.addOption("ivrle", false, "offer only Implicit VR Little Endian Transfer Syntax.");

    OptionBuilder.withArgName("maxops");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "maximum number of outstanding C-MOVE-RQ " + "it may invoke asynchronously, 1 by default.");
    opts.addOption(OptionBuilder.create("async"));

    OptionBuilder.withArgName("maxops");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("maximum number of outstanding storage operations performed "
            + "asynchronously, unlimited by default.");
    opts.addOption(OptionBuilder.create("storeasync"));

    opts.addOption("noextneg", false, "disable extended negotiation.");
    opts.addOption("rel", false, "negotiate support of relational queries and retrieval.");
    opts.addOption("datetime", false, "negotiate support of combined date and time attribute range matching.");
    opts.addOption("fuzzy", false, "negotiate support of fuzzy semantic person name attribute matching.");

    opts.addOption("retall", false,
            "negotiate private FIND SOP Classes " + "to fetch all available attributes of matching entities.");
    opts.addOption("blocked", false, "negotiate private FIND SOP Classes "
            + "to return attributes of several matching entities per FIND " + "response.");
    opts.addOption("vmf", false, "negotiate private FIND SOP Classes to "
            + "return attributes of legacy CT/MR images of one series as " + "virtual multiframe object.");
    opts.addOption("pdv1", false, "send only one PDV in one P-Data-TF PDU, pack command and data "
            + "PDV in one P-DATA-TF PDU by default.");
    opts.addOption("tcpdelay", false, "set TCP_NODELAY socket option to false, true by default");

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for TCP connect, no timeout by default");
    opts.addOption(OptionBuilder.create("connectTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("delay in ms for Socket close after sending A-ABORT, 50ms by default");
    opts.addOption(OptionBuilder.create("soclosedelay"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("period in ms to check for outstanding DIMSE-RSP, 10s by default");
    opts.addOption(OptionBuilder.create("reaper"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving C-FIND-RSP, 60s by default");
    opts.addOption(OptionBuilder.create("cfindrspTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving C-MOVE-RSP and C-GET RSP, 600s by default");
    opts.addOption(OptionBuilder.create("cmoverspTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving C-GET-RSP and C-MOVE RSP, 600s by default");
    opts.addOption(OptionBuilder.create("cgetrspTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving A-ASSOCIATE-AC, 5s by default");
    opts.addOption(OptionBuilder.create("acceptTO"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("timeout in ms for receiving A-RELEASE-RP, 5s by default");
    opts.addOption(OptionBuilder.create("releaseTO"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("maximal length in KB of received P-DATA-TF PDUs, 16KB by default");
    opts.addOption(OptionBuilder.create("rcvpdulen"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("maximal length in KB of sent P-DATA-TF PDUs, 16KB by default");
    opts.addOption(OptionBuilder.create("sndpdulen"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("set SO_RCVBUF socket option to specified value in KB");
    opts.addOption(OptionBuilder.create("sorcvbuf"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("set SO_SNDBUF socket option to specified value in KB");
    opts.addOption(OptionBuilder.create("sosndbuf"));

    OptionBuilder.withArgName("KB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("minimal buffer size to write received object to file, 1KB by default");
    opts.addOption(OptionBuilder.create("filebuf"));

    OptionGroup qrlevel = new OptionGroup();

    OptionBuilder.withDescription("perform patient level query, multiple "
            + "exclusive with -S and -I, perform study level query " + "by default.");
    OptionBuilder.withLongOpt("patient");
    qrlevel.addOption(OptionBuilder.create("P"));

    OptionBuilder.withDescription("perform series level query, multiple "
            + "exclusive with -P and -I, perform study level query " + "by default.");
    OptionBuilder.withLongOpt("series");
    qrlevel.addOption(OptionBuilder.create("S"));

    OptionBuilder.withDescription("perform instance level query, multiple "
            + "exclusive with -P and -S, perform study level query " + "by default.");
    OptionBuilder.withLongOpt("image");
    qrlevel.addOption(OptionBuilder.create("I"));

    OptionBuilder.withArgName("cuid");
    OptionBuilder.hasArgs();
    OptionBuilder.withDescription("negotiate addition private C-FIND SOP " + "class with specified UID");
    opts.addOption(OptionBuilder.create("cfind"));

    opts.addOptionGroup(qrlevel);

    OptionBuilder.withArgName("[seq/]attr=value");
    OptionBuilder.hasArgs();
    OptionBuilder.withValueSeparator('=');
    OptionBuilder.withDescription(
            "specify matching key. attr can be " + "specified by name or tag value (in hex), e.g. PatientName "
                    + "or 00100010. Attributes in nested Datasets can "
                    + "be specified by including the name/tag value of "
                    + "the sequence attribute, e.g. 00400275/00400009 "
                    + "for Scheduled Procedure Step ID in the Request " + "Attributes Sequence");
    opts.addOption(OptionBuilder.create("q"));

    OptionBuilder.withArgName("attr");
    OptionBuilder.hasArgs();
    OptionBuilder.withDescription(
            "specify additional return key. attr can " + "be specified by name or tag value (in hex).");
    opts.addOption(OptionBuilder.create("r"));

    opts.addOption("nodefret", false, "only inlcude return keys specified by -r into the request.");

    OptionBuilder.withArgName("num");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "cancel query after receive of specified " + "number of responses, no cancel by default");
    opts.addOption(OptionBuilder.create("C"));

    OptionBuilder.withArgName("aet");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("retrieve matching objects to specified " + "move destination.");
    opts.addOption(OptionBuilder.create("cmove"));

    opts.addOption("evalRetrieveAET", false, "Only Move studies not allready stored on destination AET");
    opts.addOption("lowprior", false, "LOW priority of the C-FIND/C-MOVE operation, MEDIUM by default");
    opts.addOption("highprior", false, "HIGH priority of the C-FIND/C-MOVE operation, MEDIUM by default");

    OptionBuilder.withArgName("num");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("repeat query (and retrieve) several times");
    opts.addOption(OptionBuilder.create("repeat"));

    OptionBuilder.withArgName("ms");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("delay in ms between repeated query (and retrieve), no delay by default");
    opts.addOption(OptionBuilder.create("repeatdelay"));

    opts.addOption("reuseassoc", false, "Reuse association for repeated query (and retrieve)");
    opts.addOption("closeassoc", false, "Close association between repeated query (and retrieve)");

    opts.addOption("h", "help", false, "print this message");
    opts.addOption("V", "version", false, "print the version information and exit");
    CommandLine cl = null;
    try {
        cl = new GnuParser().parse(opts, args);
    } catch (ParseException e) {
        exit("dcmqr: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = DcmQR.class.getPackage();
        System.out.println("dcmqr v" + p.getImplementationVersion());
        System.exit(0);
    }
    if (cl.hasOption('h') || cl.getArgList().size() != 1) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE);
        System.exit(0);
    }

    return cl;
}