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:org.marketcetera.ors.security.ORSAdminCLI.java

/**
 * Returns the options accepted by the CLI.
 *
 * @return the options accepted by the CLI
 */// www.  j av  a 2s.  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

public static void main(String... args) {
    if (new UnixSystem().getUid() != 0) {
        System.err.println("This command should be executed by root.");
        System.exit(MM_CTL_RET_CODE.PERMISSION_DENIED.code);
    }//  ww w .  j av a2s .c o m

    Options options = new Options();

    // Configure the CLI options
    options.addOptionGroup(getMutuallyExclusiveOptionGroup());
    options.addOptionGroup(getOptionalOptionGroup());

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

        // First get the config file
        String configFilePath = getConfig(cl);
        if (configFilePath == null) {
            System.err.println("Config file not found.");
            System.exit(MM_CTL_RET_CODE.NO_CONFIG.code);
        }

        // Set up Guice dependencies
        Injector injector = getInjector(configFilePath);
        MmCtl mmctl = new MmCtl(injector.getInstance(DataClient.class), injector.getInstance(HostConfig.class));

        MmCtlResult res = null;
        if (cl.hasOption("bind-port")) {
            String[] opts = cl.getOptionValues("bind-port");

            if (opts == null || opts.length < 2) {
                throw new ParseException("bind-port requires two " + "arguments: port ID and device name");
            }

            res = mmctl.bindPort(getPortUuid(opts[0]), opts[1]);
        } else if (cl.hasOption("unbind-port")) {
            String opt = cl.getOptionValue("unbind-port");

            res = mmctl.unbindPort(getPortUuid(opt));

        } else if (cl.hasOption("list-hosts")) {
            res = mmctl.listHosts();

        } else {
            // Only a programming error could cause this part to be
            // executed.
            throw new RuntimeException("Unknown option encountered.");
        }

        if (res.isSuccess()) {
            System.out.println(res.getMessage());
        } else {
            System.err.println(res.getMessage());
        }

        System.exit(res.getExitCode());

    } catch (ParseException e) {
        System.err.println("Error with the options: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("mm-ctl", options);
        System.exit(MM_CTL_RET_CODE.BAD_COMMAND.code);
    }
}

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 av a 2s.  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);/*w  w  w .j av  a2s.c  om*/
    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.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);

    CommandLineParser parser = new GnuParser();
    try {/*from  w  w  w  . j av  a2s .co m*/
        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/* w w w. ja v a  2  s  . c  o  m*/
 */
@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/*  ww w  .jav  a 2  s. 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);//  w  w  w  .  j  ava 2 s .com
    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') };
    }
}

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

@Override
protected void parseArgs(String[] args) throws AdeException {
    final Option helpOpt = new Option("h", "help", false, "Print help message and exit");

    OptionBuilder.withLongOpt(ALL_OPT);/*  ww  w.ja  v  a  2  s  .  c  o  m*/
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("All analysis groups");
    final Option allAnalysisGroupsOpt = OptionBuilder.create('a');

    OptionBuilder.withLongOpt(GROUPS_OPT);
    OptionBuilder.withArgName("ANALYSIs GROUPS");
    OptionBuilder.hasArgs();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Selected analysis groups");
    final Option selectAnalysisGroupsOpt = OptionBuilder.create('s');

    final OptionGroup inputAnalysisGroupsOptGroup = new OptionGroup().addOption(allAnalysisGroupsOpt)
            .addOption(selectAnalysisGroupsOpt);
    inputAnalysisGroupsOptGroup.setRequired(true);

    OptionBuilder.withLongOpt(UNSELECT_OPT);
    OptionBuilder.withArgName("ANALYSIS GROUPS");
    OptionBuilder.hasArgs();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Unselect analysis groups. Used only with '" + ALL_OPT + "'");
    final Option unselectAnalysisGroupsOpt = OptionBuilder.create('u');

    OptionBuilder.withLongOpt(DURATION_OPT);
    OptionBuilder.withArgName("DURATION (ISO 8601)");
    OptionBuilder.isRequired(false);
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "Duration from/to start/end date. Defaults to infinity. Replaces either 'start-date' or 'end-date'");
    final Option periodOpt = OptionBuilder.create();

    OptionBuilder.withLongOpt(NUM_DAYS_OPT);
    OptionBuilder.withArgName("INT");
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription("Number of days. same as '" + DURATION_OPT + "'");
    final Option numDaysOpt = OptionBuilder.create('n');

    final OptionGroup periodOptGroup = new OptionGroup().addOption(periodOpt).addOption(numDaysOpt);

    OptionBuilder.withLongOpt(START_DATE_OPT);
    OptionBuilder.withArgName("MM/dd/yyyy[ HH:mm][ Z]");
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder.withDescription(
            "Start of date range. Optional. Replaces 'duration'/'num-days' when used along with 'end-date'");
    final Option startDateOpt = OptionBuilder.create();

    OptionBuilder.withLongOpt(END_DATE_OPT);
    OptionBuilder.withArgName("MM/dd/yyyy[ HH:mm][ Z]");
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    OptionBuilder
            .withDescription("End of date range. Defaults to this moment. Replaces 'duration'/'num-days' when"
                    + " used along with 'start-date'");
    final Option endDateOpt = OptionBuilder.create();

    final Options options = new Options();
    options.addOption(helpOpt);
    options.addOptionGroup(inputAnalysisGroupsOptGroup);
    options.addOption(unselectAnalysisGroupsOpt);
    options.addOptionGroup(periodOptGroup);
    options.addOption(endDateOpt);
    options.addOption(startDateOpt);

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

    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (MissingOptionException exp) {
        new HelpFormatter().printHelp(HELP + "\nOptions:", options);
        throw new AdeUsageException("Command line parsing failed", exp);
    } catch (ParseException exp) {
        // oops, something went wrong
        throw new AdeUsageException("Argument Parsing failed", exp);
    }

    if (line.hasOption(helpOpt.getLongOpt())) {
        new HelpFormatter().printHelp(HELP, options);
        closeAll();
        System.exit(0);
    }

    if (line.hasOption(UNSELECT_OPT) && !line.hasOption(ALL_OPT)) {
        throw new AdeUsageException("'" + UNSELECT_OPT + "' cannot be used without '" + ALL_OPT + "'");
    }

    final Set<Integer> allAnalysisGroups = Ade.getAde().getDataStore().sources().getAllAnalysisGroups();
    if (line.hasOption(ALL_OPT)) {
        System.out.println("Operating on all available analysis groups");
        if (!line.hasOption(UNSELECT_OPT)) {
            m_analysisGroups = allAnalysisGroups;
        } else {
            final Set<Integer> unselectedAnalysisGroups = parseAnalysisGroups(allAnalysisGroups,
                    line.getOptionValues(UNSELECT_OPT));
            final Set<String> unselectedGroupNames = getGroupNames(unselectedAnalysisGroups);
            System.out.println("Omitting analysis groups: " + unselectedGroupNames.toString());
            m_analysisGroups = new TreeSet<Integer>(allAnalysisGroups);
            m_analysisGroups.removeAll(unselectedAnalysisGroups);
        }
    } else if (line.hasOption(GROUPS_OPT)) {
        m_analysisGroups = parseAnalysisGroups(allAnalysisGroups, line.getOptionValues(GROUPS_OPT));
        final Set<String> operatingAnalysisGroups = getGroupNames(m_analysisGroups);
        System.out.println("Operating on analysis groups: " + operatingAnalysisGroups.toString());
    }

    if ((line.hasOption(NUM_DAYS_OPT) || line.hasOption(DURATION_OPT)) && line.hasOption(START_DATE_OPT)
            && line.hasOption(END_DATE_OPT)) {
        throw new AdeUsageException("Cannot use '" + DURATION_OPT + "'/'" + NUM_DAYS_OPT + "', '"
                + START_DATE_OPT + "' and '" + END_DATE_OPT + "' together");
    }
    if (line.hasOption(NUM_DAYS_OPT)) {
        final String numDaysStr = line.getOptionValue(NUM_DAYS_OPT);
        final int numDays = Integer.parseInt(numDaysStr);
        this.m_period = Period.days(numDays);
    }
    if (line.hasOption(DURATION_OPT)) {
        final String periodStr = line.getOptionValue(DURATION_OPT);
        this.m_period = ISOPeriodFormat.standard().parsePeriod(periodStr);
    }
    if (line.hasOption(START_DATE_OPT)) {
        m_startDate = parseDate(line.getOptionValue(START_DATE_OPT));
    }
    if (line.hasOption(END_DATE_OPT)) {
        m_endDate = parseDate(line.getOptionValue(END_DATE_OPT));
    }
}

From source file:org.openmeetings.cli.Admin.java

private Options buildOptions() {
    Options options = new Options();
    OptionGroup group = new OptionGroup()
            .addOption(new OmOption("h", 0, "h", "help", false, "prints this message"))
            .addOption(new OmOption("b", 1, "b", "backup", false, "Backups OM"))
            .addOption(new OmOption("r", 2, "r", "restore", false, "Restores OM"))
            .addOption(new OmOption("i", 3, "i", "install", false, "Fill DB table, and make OM usable"))
            .addOption(new OmOption("f", 4, "f", "files", false, "File operations - statictics/cleanup"));
    group.setRequired(true);/*from  www .j a  v a 2 s.co  m*/
    options.addOptionGroup(group);
    //general
    options.addOption(new OmOption(null, "v", "verbose", false, "verbose error messages"));
    //backup/restore
    options.addOption(new OmOption("b", null, "exclude-files", false,
            "should backup exclude files [default: include]", true));
    options.addOption(new OmOption("b,r,i", "file", null, true, "file used for backup/restore/install", "b"));
    //install
    options.addOption(new OmOption("i", "user", null, true, "Login name of the default user, minimum "
            + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (mutually exclusive with 'file')"));
    options.addOption(new OmOption("i", "email", null, true,
            "Email of the default user (mutually exclusive with 'file')"));
    options.addOption(new OmOption("i", "group", null, true,
            "The name of the default user group (mutually exclusive with 'file')"));
    options.addOption(new OmOption("i", "tz", null, true,
            "Default server time zone, and time zone for the selected user (mutually exclusive with 'file')"));
    options.addOption(new OmOption("i", null, "password", true, "Password of the default user, minimum "
            + InstallationConfig.USER_LOGIN_MINIMUM_LENGTH + " characters (will be prompted if not set)",
            true));
    options.addOption(new OmOption("i", null, "system-email-address", true,
            "System e-mail address [default: " + cfg.mailReferer + "]", true));
    options.addOption(new OmOption("i", null, "smtp-server", true,
            "SMTP server for outgoing e-mails [default: " + cfg.smtpServer + "]", true));
    options.addOption(new OmOption("i", null, "smtp-port", true,
            "SMTP server for outgoing e-mails [default: " + cfg.smtpPort + "]", true));
    options.addOption(new OmOption("i", null, "email-auth-user", true,
            "Email auth username (anonymous connection will be used if not set)", true));
    options.addOption(new OmOption("i", null, "email-auth-pass", true,
            "Email auth password (anonymous connection will be used if not set)", true));
    options.addOption(
            new OmOption("i", null, "email-use-tls", false, "Is secure e-mail connection [default: no]", true));
    options.addOption(new OmOption("i", null, "skip-default-rooms", false,
            "Do not create default rooms [created by default]", true));
    options.addOption(new OmOption("i", null, "disable-frontend-register", false,
            "Do not allow front end register [allowed by default]", true));

    options.addOption(new OmOption("i", null, "db-type", true, "The type of the DB to be used", true));
    options.addOption(new OmOption("i", null, "db-host", true, "DNS name or IP address of database", true));
    options.addOption(new OmOption("i", null, "db-port", true, "Database port", true));
    options.addOption(new OmOption("i", null, "db-name", true, "The name of Openmeetings database", true));
    options.addOption(
            new OmOption("i", null, "db-user", true, "User with write access to the DB specified", true));
    options.addOption(new OmOption("i", null, "db-pass", true,
            "Password of the user with write access to the DB specified", true));
    options.addOption(new OmOption("i", null, "drop", false, "Drop database before installation", true));
    options.addOption(new OmOption("i", null, "force", false,
            "Install without checking the existence of old data in the database.", true));

    return options;
}