Example usage for org.apache.commons.cli OptionGroup OptionGroup

List of usage examples for org.apache.commons.cli OptionGroup OptionGroup

Introduction

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

Prototype

OptionGroup

Source Link

Usage

From source file:org.marketcetera.ors.security.ORSAdminCLI.java

/**
 * Returns the options accepted by the CLI.
 *
 * @return the options accepted by the CLI
 *///w  w  w  . j a  va2 s. c  o  m
private static Options options() {
    Options opts = new Options();
    opts.addOption(OptionBuilder.hasArg().withArgName(CLI_ARG_LOGIN_VALUE.getText())
            .withDescription(CLI_PARM_USER.getText()).isRequired(true).create(OPT_CURRENT_USER));
    opts.addOption(OptionBuilder.hasArg().withArgName(CLI_ARG_LOGIN_PASSWORD_VALUE.getText())
            .withDescription(CLI_PARM_PASSWORD.getText()).isRequired(false).create(OPT_CURRENT_PASSWORD));

    OptionGroup commands = new OptionGroup();
    commands.setRequired(true);
    commands.addOption(OptionBuilder.withLongOpt(CMD_LIST_USERS).withDescription(CLI_CMD_LIST_USERS.getText())
            .isRequired().create());
    commands.addOption(OptionBuilder.withLongOpt(CMD_ADD_USER).withDescription(CLI_CMD_ADD_USER.getText())
            .isRequired().create());
    commands.addOption(OptionBuilder.withLongOpt(CMD_DELETE_USER).withDescription(CLI_CMD_DELETE_USER.getText())
            .isRequired().create());
    commands.addOption(OptionBuilder.withLongOpt(CMD_RESTORE_USER)
            .withDescription(CLI_CMD_RESTORE_USER.getText()).isRequired().create());
    commands.addOption(OptionBuilder.withLongOpt(CMD_CHANGE_PASS)
            .withDescription(CLI_CMD_CHANGE_PASSWORD.getText()).isRequired().create());
    commands.addOption(OptionBuilder.withLongOpt(CMD_CHANGE_SUPERUSER)
            .withDescription(CLI_CMD_CHANGE_SUPERUSER.getText()).isRequired().create());
    opts.addOptionGroup(commands);
    //Add optional arguments
    opts.addOption(OptionBuilder.withLongOpt("username"). //$NON-NLS-1$
            hasArg().withArgName(CLI_ARG_USER_NAME_VALUE.getText()).withDescription(CLI_PARM_OP_USER.getText())
            .isRequired(false).create(OPT_OPERATED_USER));
    opts.addOption(OptionBuilder.withLongOpt("password"). //$NON-NLS-1$
            hasArg().withArgName(CLI_ARG_USER_PASSWORD_VALUE.getText())
            .withDescription(CLI_PARM_OP_PASSWORD.getText()).isRequired(false).create(OPT_OPERATED_PASSWORD));
    opts.addOption(OptionBuilder.withLongOpt("superuser"). //$NON-NLS-1$
            hasArg().withArgName(CLI_ARG_USER_SUPERUSER_VALUE.getText())
            .withDescription(CLI_PARM_OP_SUPERUSER.getText()).isRequired(false).create(OPT_OPERATED_SUPERUSER));
    opts.addOption(OptionBuilder.withLongOpt("active"). //$NON-NLS-1$
            hasArg().withArgName(CLI_ARG_USER_ACTIVE_VALUE.getText())
            .withDescription(CLI_PARM_OP_ACTIVE.getText()).isRequired(false).create(OPT_OPERATED_ACTIVE));
    return opts;
}

From source file:org.midonet.midolman.tools.MmCtl.java

private static OptionGroup getOptionalOptionGroup() {
    OptionGroup optionalGroup = new OptionGroup();

    OptionBuilder.hasArg();//from   w w w.  ja  va 2  s.c  om
    OptionBuilder.withLongOpt("config");
    OptionBuilder.withDescription("MM configuration file");
    optionalGroup.addOption(OptionBuilder.create());

    optionalGroup.setRequired(false);
    return optionalGroup;
}

From source file:org.midonet.midolman.tools.MmCtl.java

private static OptionGroup getMutuallyExclusiveOptionGroup() {

    // The command line tool can only accept one of these options:
    OptionGroup mutuallyExclusiveOptions = new OptionGroup();

    OptionBuilder.hasArgs(2);/*w ww .ja  va  2  s .c  om*/
    OptionBuilder.isRequired();
    OptionBuilder.withLongOpt("bind-port");
    OptionBuilder.withDescription("Bind a port to an interface");
    mutuallyExclusiveOptions.addOption(OptionBuilder.create());

    OptionBuilder.hasArg();
    OptionBuilder.isRequired();
    OptionBuilder.withLongOpt("unbind-port");
    OptionBuilder.withDescription("Unbind a port from an interface");
    mutuallyExclusiveOptions.addOption(OptionBuilder.create());

    OptionBuilder.withLongOpt("list-hosts");
    OptionBuilder.withDescription("List MidolMan agents in the system");
    mutuallyExclusiveOptions.addOption(OptionBuilder.create());

    // make sure that there is at least one.
    mutuallyExclusiveOptions.setRequired(true);

    return mutuallyExclusiveOptions;
}

From source file:org.midonet.mmdpctl.Mmdpctl.java

public static void main(String... args) {
    Options options = new Options();

    // The command line tool can only accept one of these options:
    OptionGroup mutuallyExclusiveOptions = new OptionGroup();

    OptionBuilder.withDescription("List all the installed datapaths");
    OptionBuilder.isRequired();/*  w  w  w.  j a v a2 s .c  o  m*/
    OptionBuilder.withLongOpt("list-dps");
    mutuallyExclusiveOptions.addOption(OptionBuilder.create());

    OptionBuilder.withDescription("Show all the information related to a given datapath.");
    OptionBuilder.hasArg();
    OptionBuilder.isRequired();
    OptionBuilder.withLongOpt("show-dp");
    mutuallyExclusiveOptions.addOption(OptionBuilder.create());

    OptionBuilder.withDescription("Show all the flows installed for a given datapath.");
    OptionBuilder.hasArg();
    OptionBuilder.isRequired();
    OptionBuilder.withLongOpt("dump-dp");
    mutuallyExclusiveOptions.addOption(OptionBuilder.create());

    OptionBuilder.withDescription("Add a new datapath.");
    OptionBuilder.hasArg();
    OptionBuilder.withLongOpt("add-dp");
    mutuallyExclusiveOptions.addOption(OptionBuilder.create());

    OptionBuilder.withDescription("Delete a datapath.");
    OptionBuilder.hasArg();
    OptionBuilder.withLongOpt("delete-dp");
    mutuallyExclusiveOptions.addOption(OptionBuilder.create());

    // make sure that there is at least one.
    mutuallyExclusiveOptions.setRequired(true);
    options.addOptionGroup(mutuallyExclusiveOptions);

    // add an optional timeout to the command.
    OptionBuilder.withDescription(
            "Specifies a timeout in seconds. " + "If the program is not able to get the results in less than "
                    + "this amount of time it will stop and return with an error code");
    OptionBuilder.hasArg();
    OptionBuilder.withLongOpt("timeout");
    options.addOption(OptionBuilder.create());

    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cl = parser.parse(options, args);

        Mmdpctl mmdpctl = new Mmdpctl();

        // check if the user sets a (correct) timeout.
        if (cl.hasOption("timeout")) {
            String timeoutString = cl.getOptionValue("timeout");
            Integer timeout = Integer.parseInt(timeoutString);
            if (timeout > 0) {
                log.info("Installing a timeout of {} seconds", timeout);
                mmdpctl.setTimeout(timeout);
            } else {
                System.out.println("The timeout needs to be a positive number, bigger than 0.");
                System.exit(1);
            }
        }

        if (cl.hasOption("list-dps")) {
            System.exit(mmdpctl.execute(new ListDatapathsCommand()));
        } else if (cl.hasOption("show-dp")) {
            System.exit(mmdpctl.execute(new GetDatapathCommand(cl.getOptionValue("show-dp"))));
        } else if (cl.hasOption("dump-dp")) {
            System.exit(mmdpctl.execute(new DumpDatapathCommand(cl.getOptionValue("dump-dp"))));
        } else if (cl.hasOption("add-dp")) {
            System.exit(mmdpctl.execute(new AddDatapathCommand(cl.getOptionValue("add-dp"))));
        } else if (cl.hasOption("delete-dp")) {
            System.exit(mmdpctl.execute(new DeleteDatapathCommand(cl.getOptionValue("delete-dp"))));
        }

    } catch (ParseException e) {
        showHelpAndExit(options, e.getMessage());
    }

    System.exit(0);
}

From source file:org.mrgeo.cmd.ingest.IngestImage.java

public static Options createOptions() {
    Options result = MrGeo.createOptions();

    Option output = new Option("o", "output", true, "MrsPyramid image name");
    output.setRequired(true);//from   ww w  .  j  av a2 s. c  o  m
    result.addOption(output);

    Option cat = new Option("c", "categorical", false, "Input [pixels] are categorical values");
    cat.setRequired(false);
    result.addOption(cat);

    Option pyramid = new Option("sp", "skippyramid", false, "Skip building pyramids");
    pyramid.setRequired(false);
    result.addOption(pyramid);

    Option recurse = new Option("nr", "norecursion", false, "Do not recurse through sub-directories");
    recurse.setRequired(false);
    result.addOption(recurse);

    Option nodata = new Option("nd", "nodata", true, "override nodata value");
    //nodata.setArgPattern(argPattern, limit);
    nodata.setRequired(false);
    result.addOption(nodata);

    Option tags = new Option("t", "tags", true, "tags (fmt: \"k1,v:k2,v:...\"");
    tags.setRequired(false);
    result.addOption(tags);

    Option notags = new Option("nt", "notags", false, "Do not automatically load tags from source images");
    notags.setRequired(false);
    result.addOption(notags);

    OptionGroup aggregators = new OptionGroup();

    Option mean = new Option("m", "mean", false, "Mean (Average) Pyramid Pixel Resampling Method");
    mean.setRequired(false);
    aggregators.addOption(mean);

    Option sum = new Option("s", "sum", false, "Summing Pyramid Pixel Resampling Method");
    sum.setRequired(false);
    aggregators.addOption(sum);

    Option nearest = new Option("n", "nearest", false, "Nearest Pyramid Pixel Resampling Method");
    nearest.setRequired(false);
    aggregators.addOption(nearest);

    Option min = new Option("min", "minimum", false, "Minimum Pyramid Pixel Resampling Method");
    min.setRequired(false);
    aggregators.addOption(min);

    Option max = new Option("max", "maximum", false, "Maximum Pyramid Pixel Resampling Method");
    max.setRequired(false);
    aggregators.addOption(max);

    Option minavgpair = new Option("minavgpair", "miminumaveragepair", false,
            "Minimum Average Pair Pyramid Pixel Resampling Method");
    minavgpair.setRequired(false);
    aggregators.addOption(minavgpair);

    result.addOptionGroup(aggregators);

    Option local = new Option("lc", "local", false, "Use local files for ingest, good for small ingests");
    local.setRequired(false);
    result.addOption(local);

    Option quick = new Option("q", "quick", false, "Quick ingest (for small files only)");
    quick.setRequired(false);
    result.addOption(quick);

    Option zoom = new Option("z", "zoom", true, "force zoom level");
    zoom.setRequired(false);
    result.addOption(zoom);

    Option skippre = new Option("sk", "skippreprocessing", false,
            "Skip the preprocessing step (must specify zoom)");
    skippre.setRequired(false);
    result.addOption(skippre);

    Option protectionLevelOption = new Option("pl", "protectionLevel", true, "Protection level");
    // If mrgeo.conf security.classification.required is true and there is no
    // security.classification.default, then the security classification
    // argument is required, otherwise it is not.
    Properties props = MrGeoProperties.getInstance();
    String protectionLevelRequired = props.getProperty(MrGeoConstants.MRGEO_PROTECTION_LEVEL_REQUIRED, "false")
            .trim();
    String protectionLevelDefault = props.getProperty(MrGeoConstants.MRGEO_PROTECTION_LEVEL_DEFAULT, "");
    if (protectionLevelRequired.equalsIgnoreCase("true") && protectionLevelDefault.isEmpty()) {
        protectionLevelOption.setRequired(true);
    } else {
        protectionLevelOption.setRequired(false);
    }
    result.addOption(protectionLevelOption);

    return result;
}

From source file:org.nuxeo.launcher.NuxeoLauncher.java

/**
 * @since 5.6/*  ww w. ja  v a2s  . c  om*/
 */
protected static void initParserOptions() {
    if (launcherOptions == null) {
        launcherOptions = new Options();
        // help option
        OptionBuilder.withLongOpt(OPTION_HELP);
        OptionBuilder.withDescription(OPTION_HELP_DESC);
        launcherOptions.addOption(OptionBuilder.create("h"));
        // Quiet option
        OptionBuilder.withLongOpt(OPTION_QUIET);
        OptionBuilder.withDescription(OPTION_QUIET_DESC);
        launcherOptions.addOption(OptionBuilder.create("q"));
        // Debug option
        OptionBuilder.withLongOpt(OPTION_DEBUG);
        OptionBuilder.withDescription(OPTION_DEBUG_DESC);
        launcherOptions.addOption(OptionBuilder.create("d"));
        // Debug category option
        OptionBuilder.withDescription(OPTION_DEBUG_CATEGORY_DESC);
        OptionBuilder.hasArg();
        launcherOptions.addOption(OptionBuilder.create(OPTION_DEBUG_CATEGORY));
        OptionGroup outputOptions = new OptionGroup();
        // Hide deprecation warnings option
        OptionBuilder.withLongOpt(OPTION_HIDE_DEPRECATION);
        OptionBuilder.withDescription(OPTION_HIDE_DEPRECATION_DESC);
        outputOptions.addOption(OptionBuilder.create());
        // XML option
        OptionBuilder.withLongOpt(OPTION_XML);
        OptionBuilder.withDescription(OPTION_XML_DESC);
        outputOptions.addOption(OptionBuilder.create());
        // JSON option
        OptionBuilder.withLongOpt(OPTION_JSON);
        OptionBuilder.withDescription(OPTION_JSON_DESC);
        outputOptions.addOption(OptionBuilder.create());
        launcherOptions.addOptionGroup(outputOptions);
        // GUI option
        OptionBuilder.withLongOpt(OPTION_GUI);
        OptionBuilder.hasArg();
        OptionBuilder.withArgName("true|false");
        OptionBuilder.withDescription(OPTION_GUI_DESC);
        launcherOptions.addOption(OptionBuilder.create());
        // Package management option
        OptionBuilder.withLongOpt(OPTION_NODEPS);
        OptionBuilder.withDescription(OPTION_NODEPS_DESC);
        launcherOptions.addOption(OptionBuilder.create());
        // Relax on target platform option
        OptionBuilder.withLongOpt(OPTION_RELAX);
        OptionBuilder.hasArg();
        OptionBuilder.withArgName("true|false|ask");
        OptionBuilder.withDescription(OPTION_RELAX_DESC);
        launcherOptions.addOption(OptionBuilder.create());
        // Accept option
        OptionBuilder.withLongOpt(OPTION_ACCEPT);
        OptionBuilder.hasArg();
        OptionBuilder.withArgName("true|false|ask");
        OptionBuilder.withDescription(OPTION_ACCEPT_DESC);
        launcherOptions.addOption(OptionBuilder.create());
    }
}

From source file:org.objectweb.proactive.extensions.ssl.KeyStoreCreator.java

public void parseOptions(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(OPT_HELP[0], OPT_HELP[1], false, OPT_HELP[2]);
    options.addOption(OPT_KEYSTORE[0], OPT_KEYSTORE[1], true, OPT_KEYSTORE[2]);

    OptionGroup group = new OptionGroup();
    group.addOption(new Option(OPT_CREATE[0], OPT_CREATE[1], false, OPT_CREATE[2]));
    group.addOption(new Option(OPT_UPDATE[0], OPT_UPDATE[1], false, OPT_UPDATE[2]));
    group.addOption(new Option(OPT_VERIFY[0], OPT_VERIFY[1], false, OPT_VERIFY[2]));
    options.addOptionGroup(group);//  ww w  . j a  v  a  2s  .co  m

    CommandLineParser parser = new GnuParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption(OPT_HELP[0])) {
            printHelp(options);
        }

        String keyStore = null;
        if (cmd.hasOption(OPT_KEYSTORE[0])) {
            keyStore = cmd.getOptionValue(OPT_KEYSTORE[0]);
        } else {
            System.err.println("The " + OPT_KEYSTORE[1] + " option is mandatory");
            return;
        }

        boolean hasAction = false;
        if (cmd.hasOption(OPT_CREATE[0])) {
            hasAction = true;
            if (!this.create(keyStore)) {
                System.exit(1);
            }
        }

        if (cmd.hasOption(OPT_UPDATE[0])) {
            hasAction = true;
            if (!this.update(keyStore)) {
                System.exit(1);
            }
        }

        if (cmd.hasOption(OPT_VERIFY[0])) {
            hasAction = true;
            if (!this.verify(keyStore)) {
                System.exit(1);
            }
        }

        if (!hasAction) {
            System.err.println("One of " + OPT_CREATE[1] + ", " + OPT_UPDATE[1] + ", " + OPT_VERIFY[1]
                    + " has is needed\n");
            printHelp(options);
        }
    } catch (ParseException e) {
        System.err.println(e);
    }
}

From source file:org.openmainframe.ade.ext.main.AdeUtilMain.java

/**
 * Parse the input arguments//from www .  j  av a  2 s  .c om
 */
@SuppressWarnings("static-access")
@Override
protected void parseArgs(String[] args) throws AdeUsageException {
    Options options = new Options();

    Option helpOpt = new Option("h", "help", false, "Print help message and exit");
    options.addOption(helpOpt);

    Option versionOpt = OptionBuilder.withLongOpt("version").hasArg(false).isRequired(false)
            .withDescription("Print current Ade version (JAR) and exit").create('v');
    options.addOption(versionOpt);

    Option dbVersionOpt = OptionBuilder.withLongOpt("db-version")
            .withDescription("Print current Ade DB version and exit").create('b');
    options.addOption(dbVersionOpt);

    Option outputFileOpt = OptionBuilder.withLongOpt("output").hasArg(true).withArgName("FILE")
            .isRequired(false).withDescription("Output file name (where relevant)").create('o');
    options.addOption(outputFileOpt);

    OptionGroup optGroup = new OptionGroup();
    optGroup.setRequired(false);

    Option DumpModelDebugOpt = OptionBuilder.withLongOpt("debugPrint").hasArg(true).withArgName("MODEL FILE")
            .isRequired(false).withDescription("Extract a text version of a model debug information and exit")
            .create('d');
    optGroup.addOption(DumpModelDebugOpt);

    Option verifyFlowOpt = OptionBuilder.withLongOpt("verifyFlow").hasArg(true).withArgName("FLOW FILE")
            .isRequired(false).withDescription("Verify the flow file matches the XSD standard and exit")
            .create('f');
    optGroup.addOption(verifyFlowOpt);

    options.addOptionGroup(optGroup);

    CommandLineParser parser = new GnuParser();
    CommandLine line = null;

    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (MissingOptionException exp) {
        System.out.println("Command line parsing failed.  Reason: " + exp.getMessage());
        System.out.println();
        new HelpFormatter().printHelp(ControlDB.class.getName(), options);
        System.exit(0);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        throw new AdeUsageException("Argument Parsing failed", exp);
    }

    if (line.hasOption('h')) {
        new HelpFormatter().printHelp(this.getClass().getSimpleName(), options);
        System.exit(0);
    }
    if (line.hasOption(helpOpt.getLongOpt())) {
        new HelpFormatter().printHelp(getClass().getSimpleName(), options);
    }

    if (line.hasOption(outputFileOpt.getLongOpt())) {
        m_outputFile = new File(line.getOptionValue(outputFileOpt.getLongOpt()));
    }

    m_inputFile = null;

    m_cmd = null;

    if (line.hasOption('v')) {
        m_cmd = "version";
    }

    if (line.hasOption('b')) {
        m_cmd = "db-version";
    }

    if (line.hasOption('d')) {
        m_inputFile = new File(line.getOptionValue(DumpModelDebugOpt.getLongOpt()));
        m_cmd = "debugPrint";
    }

    if (line.hasOption('f')) {
        m_inputFilename = line.getOptionValue(verifyFlowOpt.getLongOpt());
        m_cmd = "verifyFlow";
    }

}

From source file:org.openmainframe.ade.main.AdeUtilMain.java

@SuppressWarnings("static-access")
@Override/*from w  w w . j a va 2s . co  m*/
protected void parseArgs(String[] args) throws AdeException {
    Options options = new Options();

    Option helpOpt = new Option("h", "help", false, "Print help message and exit");
    options.addOption(helpOpt);

    Option versionOpt = OptionBuilder.withLongOpt("version").hasArg(false).isRequired(false)
            .withDescription("Print current Ade version (JAR) and exit").create('V');
    options.addOption(versionOpt);

    Option dbVersionOpt = OptionBuilder.withLongOpt("db-version")
            .withDescription("Print current Ade DB version and exit").create();
    options.addOption(dbVersionOpt);

    Option outputFileOpt = OptionBuilder.withLongOpt("output").hasArg(true).withArgName("FILE")
            .isRequired(false).withDescription("Output file name (where relevant)").create('o');

    options.addOption(outputFileOpt);

    OptionGroup optGroup = new OptionGroup();
    optGroup.setRequired(false);

    Option DumpModelOpt = OptionBuilder.withLongOpt("model").hasArg(true).withArgName("MODEL FILE")
            .isRequired(false).withDescription("Extract a text version of a model (csv) and exit").create('m');
    optGroup.addOption(DumpModelOpt);

    Option DumpModelDebugOpt = OptionBuilder.withLongOpt("debugPrint").hasArg(true).withArgName("MODEL FILE")
            .isRequired(false).withDescription("Extract a text version of a model debug information and exit")
            .create('d');
    optGroup.addOption(DumpModelDebugOpt);

    Option verifyFlowOpt = OptionBuilder.withLongOpt("verifyFlow").hasArg(true).withArgName("FLOW FILE")
            .isRequired(false).withDescription("Verify the flow file matches the XSD standard and exit")
            .create('f');
    optGroup.addOption(verifyFlowOpt);

    options.addOptionGroup(optGroup);

    CommandLineParser parser = new GnuParser();
    CommandLine line = null;

    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (MissingOptionException exp) {
        System.out.println("Command line parsing failed.  Reason: " + exp.getMessage());
        System.out.println();
        new HelpFormatter().printHelp(ControlDB.class.getName(), options);
        System.exit(0);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        throw new AdeUsageException("Argument Parsing failed", exp);
    }

    if (line.hasOption(helpOpt.getLongOpt())) {
        new HelpFormatter().printHelp(getClass().getSimpleName(), options);
        closeAll();
        System.exit(0);
    }
    if (line.hasOption(versionOpt.getLongOpt())) {
        System.out.println("Current Ade version (JAR): " + Ade.getAde().getVersion());
        closeAll();
        System.exit(0);
    }
    if (line.hasOption(dbVersionOpt.getLongOpt())) {
        System.out.println("Current Ade DB version: " + Ade.getAde().getDbVersion());
        closeAll();
        System.exit(0);
    }

    File outputFile = null;
    if (line.hasOption(outputFileOpt.getLongOpt())) {
        outputFile = new File(line.getOptionValue(outputFileOpt.getLongOpt()));
    }

    if (line.hasOption(DumpModelDebugOpt.getLongOpt())) {
        File modelFile = new File(line.getOptionValue(DumpModelDebugOpt.getLongOpt()));
        dumpModelDebug(modelFile, outputFile);
    }
    if (line.hasOption(verifyFlowOpt.getLongOpt())) {
        String flowFilename = line.getOptionValue(verifyFlowOpt.getLongOpt());
        File flowFile = new File(flowFilename);
        try {
            validateGood(flowFile);
        } catch (Exception e) {
            throw new AdeUsageException("Failed when verifiying " + flowFile.getName(), e);
        }
    }

}

From source file:org.openmainframe.ade.main.ControlDB.java

@Override
protected void parseArgs(String[] args) throws AdeException {

    final Option helpOpt = new Option("h", "help", false, "Print help message and exit");
    final Option forceOpt = new Option("f", "force", false, "Force operation. Do not prompt for confirmation");

    OptionBuilder.withLongOpt("create");
    OptionBuilder.hasArg(false);//from  w  ww  .j a  v a2 s.co  m
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Create Ade DB tables");
    final Option createOpt = OptionBuilder.create('c');

    OptionBuilder.withLongOpt("drop");
    OptionBuilder.hasArg(false);
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Drops all Ade DB tables, and clears the data store dictionaries");
    final Option deleteOpt = OptionBuilder.create('d');

    OptionBuilder.withLongOpt("reset");
    OptionBuilder.hasArg(false);
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Clears all Ade DB tables content");
    final Option resetOpt = OptionBuilder.create('r');

    OptionBuilder.withLongOpt("query");
    OptionBuilder.hasArg();
    OptionBuilder.withArgName("SQL query string");
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Performs the input query");
    final Option queryOpt = OptionBuilder.create('q');

    final OptionGroup actionGroupOpt = new OptionGroup().addOption(createOpt).addOption(deleteOpt)
            .addOption(resetOpt).addOption(queryOpt);
    actionGroupOpt.setRequired(true);

    final Options options = new Options();
    options.addOption(helpOpt);
    options.addOption(forceOpt);
    options.addOptionGroup(actionGroupOpt);

    final CommandLineParser parser = new GnuParser();
    CommandLine line = null;

    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (MissingOptionException exp) {
        logger.error("Command line parsing failed.", exp);
        new HelpFormatter().printHelp(ControlDB.class.getName(), options);
        System.exit(0);
    } catch (ParseException exp) {
        // oops, something went wrong
        logger.error("Parsing failed.  Reason: " + exp.getMessage());
        throw new AdeUsageException("Argument Parsing failed", exp);
    }

    if (line.hasOption('h')) {
        new HelpFormatter().printHelp(getClass().getSimpleName(), options);
        closeAll();
        System.exit(0);
    }

    if (line.hasOption('f')) {
        m_forceOp = true;
    }

    if (line.hasOption('c')) {
        m_op = ControlDBOperator.Create;
    } else if (line.hasOption('d')) {
        m_op = ControlDBOperator.Drop;
    } else if (line.hasOption('r')) {
        m_op = ControlDBOperator.Reset;
    } else if (line.hasOption('q')) {
        m_op = ControlDBOperator.Query;
        m_args = new String[] { line.getOptionValue('q') };
    }
}