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

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

Introduction

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

Prototype

public OptionGroup addOption(Option option) 

Source Link

Document

Add the specified Option to this group.

Usage

From source file:org.apache.sentry.cli.tools.SentryShellCommon.java

protected OptionGroup getMainOptions() {
    OptionGroup simpleShellOptGroup = new OptionGroup();
    Option crOpt = new Option("cr", "create_role", false, "Create role");
    crOpt.setRequired(false);//from w w w.  ja  v  a  2  s .  c  om

    Option drOpt = new Option("dr", "drop_role", false, "Drop role");
    drOpt.setRequired(false);

    Option argOpt = new Option("arg", "add_role_group", false, "Add role to group");
    argOpt.setRequired(false);

    Option drgOpt = new Option("drg", "delete_role_group", false, "Delete role from group");
    drgOpt.setRequired(false);

    Option gprOpt = new Option("gpr", "grant_privilege_role", false, "Grant privilege to role");
    gprOpt.setRequired(false);

    Option rprOpt = new Option("rpr", "revoke_privilege_role", false, "Revoke privilege from role");
    rprOpt.setRequired(false);

    Option lrOpt = new Option("lr", "list_role", false, "List role");
    lrOpt.setRequired(false);

    Option lpOpt = new Option("lp", "list_privilege", false, "List privilege");
    lpOpt.setRequired(false);

    Option lgOpt = new Option("lg", "list_group", false, "List groups");
    lgOpt.setRequired(false);

    // required args group
    simpleShellOptGroup.addOption(crOpt);
    simpleShellOptGroup.addOption(drOpt);
    simpleShellOptGroup.addOption(argOpt);
    simpleShellOptGroup.addOption(drgOpt);
    simpleShellOptGroup.addOption(gprOpt);
    simpleShellOptGroup.addOption(rprOpt);
    simpleShellOptGroup.addOption(lrOpt);
    simpleShellOptGroup.addOption(lpOpt);
    simpleShellOptGroup.addOption(lgOpt);
    simpleShellOptGroup.setRequired(true);
    return simpleShellOptGroup;
}

From source file:org.apache.sentry.cli.tools.SentryShellIndexer.java

@Override
protected OptionGroup getMainOptions() {
    OptionGroup mainOptions = super.getMainOptions();
    Option mgrOpt = new Option("mgr", "migrate", false, "Migrate ini file to Sentry service");
    mgrOpt.setRequired(false);/*from   ww  w . ja v a 2  s.  co m*/
    mainOptions.addOption(mgrOpt);
    return mainOptions;
}

From source file:org.apache.sentry.provider.db.tools.SentrySchemaTool.java

@SuppressWarnings("static-access")
private static void initOptions(Options cmdLineOptions) {
    Option help = new Option("help", "print this message");
    Option upgradeOpt = new Option("upgradeSchema", "Schema upgrade");
    Option upgradeFromOpt = OptionBuilder.withArgName("upgradeFrom").hasArg()
            .withDescription("Schema upgrade from a version").create("upgradeSchemaFrom");
    Option initOpt = new Option("initSchema", "Schema initialization");
    Option initToOpt = OptionBuilder.withArgName("initTo").hasArg()
            .withDescription("Schema initialization to a version").create("initSchemaTo");
    Option infoOpt = new Option("info", "Show config and schema details");

    OptionGroup optGroup = new OptionGroup();
    optGroup.addOption(upgradeOpt).addOption(initOpt).addOption(help).addOption(upgradeFromOpt)
            .addOption(initToOpt).addOption(infoOpt);
    optGroup.setRequired(true);/*www.  ja  va2s .c o  m*/

    Option userNameOpt = OptionBuilder.withArgName("user").hasArg()
            .withDescription("Override config file user name").create("userName");
    Option passwdOpt = OptionBuilder.withArgName("password").hasArg()
            .withDescription("Override config file password").create("passWord");
    Option dbTypeOpt = OptionBuilder.withArgName("databaseType").hasArg()
            .withDescription("Metastore database type [" + SentrySchemaHelper.DB_DERBY + ","
                    + SentrySchemaHelper.DB_MYSQL + "," + SentrySchemaHelper.DB_ORACLE + ","
                    + SentrySchemaHelper.DB_POSTGRACE + "," + SentrySchemaHelper.DB_DB2 + "]")
            .create("dbType");
    Option dbOpts = OptionBuilder.withArgName("databaseOpts").hasArgs()
            .withDescription("Backend DB specific options").create("dbOpts");

    Option dryRunOpt = new Option("dryRun", "list SQL scripts (no execute)");
    Option verboseOpt = new Option("verbose", "only print SQL statements");

    Option configOpt = OptionBuilder.withArgName("confName").hasArgs()
            .withDescription("Sentry Service configuration file").isRequired(true)
            .create(ServiceConstants.ServiceArgs.CONFIG_FILE_LONG);

    cmdLineOptions.addOption(help);
    cmdLineOptions.addOption(dryRunOpt);
    cmdLineOptions.addOption(userNameOpt);
    cmdLineOptions.addOption(passwdOpt);
    cmdLineOptions.addOption(dbTypeOpt);
    cmdLineOptions.addOption(verboseOpt);
    cmdLineOptions.addOption(dbOpts);
    cmdLineOptions.addOption(configOpt);
    cmdLineOptions.addOptionGroup(optGroup);
}

From source file:org.apache.sentry.provider.db.tools.SentryShellCommon.java

/**
 * parse arguments//from  ww  w  .  jav a2s. co  m
 *
 * <pre>
 *   -conf,--sentry_conf             <filepath>                 sentry config file path
 *   -cr,--create_role            -r <rolename>                 create role
 *   -dr,--drop_role              -r <rolename>                 drop role
 *   -arg,--add_role_group        -r <rolename>  -g <groupname> add role to group
 *   -drg,--delete_role_group     -r <rolename>  -g <groupname> delete role from group
 *   -gpr,--grant_privilege_role  -r <rolename>  -p <privilege> grant privilege to role
 *   -rpr,--revoke_privilege_role -r <rolename>  -p <privilege> revoke privilege from role
 *   -lr,--list_role              -g <groupname>                list roles for group
 *   -lp,--list_privilege         -r <rolename>                 list privilege for role
 *   -t,--type                    <typeame>                     the shell for hive model or generic model
 * </pre>
 *
 * @param args
 */
protected boolean parseArgs(String[] args) {
    Options simpleShellOptions = new Options();

    Option crOpt = new Option("cr", "create_role", false, "Create role");
    crOpt.setRequired(false);

    Option drOpt = new Option("dr", "drop_role", false, "Drop role");
    drOpt.setRequired(false);

    Option argOpt = new Option("arg", "add_role_group", false, "Add role to group");
    argOpt.setRequired(false);

    Option drgOpt = new Option("drg", "delete_role_group", false, "Delete role from group");
    drgOpt.setRequired(false);

    Option gprOpt = new Option("gpr", "grant_privilege_role", false, "Grant privilege to role");
    gprOpt.setRequired(false);

    Option rprOpt = new Option("rpr", "revoke_privilege_role", false, "Revoke privilege from role");
    rprOpt.setRequired(false);

    Option lrOpt = new Option("lr", "list_role", false, "List role");
    lrOpt.setRequired(false);

    Option lpOpt = new Option("lp", "list_privilege", false, "List privilege");
    lpOpt.setRequired(false);

    // required args group
    OptionGroup simpleShellOptGroup = new OptionGroup();
    simpleShellOptGroup.addOption(crOpt);
    simpleShellOptGroup.addOption(drOpt);
    simpleShellOptGroup.addOption(argOpt);
    simpleShellOptGroup.addOption(drgOpt);
    simpleShellOptGroup.addOption(gprOpt);
    simpleShellOptGroup.addOption(rprOpt);
    simpleShellOptGroup.addOption(lrOpt);
    simpleShellOptGroup.addOption(lpOpt);
    simpleShellOptGroup.setRequired(true);
    simpleShellOptions.addOptionGroup(simpleShellOptGroup);

    // optional args
    Option pOpt = new Option("p", "privilege", true, OPTION_DESC_PRIVILEGE);
    pOpt.setRequired(false);
    simpleShellOptions.addOption(pOpt);

    Option gOpt = new Option("g", "groupname", true, OPTION_DESC_GROUP_NAME);
    gOpt.setRequired(false);
    simpleShellOptions.addOption(gOpt);

    Option rOpt = new Option("r", "rolename", true, OPTION_DESC_ROLE_NAME);
    rOpt.setRequired(false);
    simpleShellOptions.addOption(rOpt);

    // this argument should be parsed in the bin/sentryShell
    Option tOpt = new Option("t", "type", true, "[hive|solr|sqoop|.....]");
    tOpt.setRequired(false);
    simpleShellOptions.addOption(tOpt);

    // file path of sentry-site
    Option sentrySitePathOpt = new Option("conf", "sentry_conf", true, OPTION_DESC_CONF);
    sentrySitePathOpt.setRequired(true);
    simpleShellOptions.addOption(sentrySitePathOpt);

    // help option
    Option helpOpt = new Option("h", "help", false, OPTION_DESC_HELP);
    helpOpt.setRequired(false);
    simpleShellOptions.addOption(helpOpt);

    // this Options is parsed first for help option
    Options helpOptions = new Options();
    helpOptions.addOption(helpOpt);

    try {
        Parser parser = new GnuParser();

        // parse help option first
        CommandLine cmd = parser.parse(helpOptions, args, true);
        for (Option opt : cmd.getOptions()) {
            if (opt.getOpt().equals("h")) {
                // get the help option, print the usage and exit
                usage(simpleShellOptions);
                return false;
            }
        }

        // without help option
        cmd = parser.parse(simpleShellOptions, args);

        for (Option opt : cmd.getOptions()) {
            if (opt.getOpt().equals("p")) {
                privilegeStr = opt.getValue();
            } else if (opt.getOpt().equals("g")) {
                groupName = opt.getValue();
            } else if (opt.getOpt().equals("r")) {
                roleName = opt.getValue();
            } else if (opt.getOpt().equals("cr")) {
                isCreateRole = true;
                roleNameRequired = true;
            } else if (opt.getOpt().equals("dr")) {
                isDropRole = true;
                roleNameRequired = true;
            } else if (opt.getOpt().equals("arg")) {
                isAddRoleGroup = true;
                roleNameRequired = true;
                groupNameRequired = true;
            } else if (opt.getOpt().equals("drg")) {
                isDeleteRoleGroup = true;
                roleNameRequired = true;
                groupNameRequired = true;
            } else if (opt.getOpt().equals("gpr")) {
                isGrantPrivilegeRole = true;
                roleNameRequired = true;
                privilegeStrRequired = true;
            } else if (opt.getOpt().equals("rpr")) {
                isRevokePrivilegeRole = true;
                roleNameRequired = true;
                privilegeStrRequired = true;
            } else if (opt.getOpt().equals("lr")) {
                isListRole = true;
            } else if (opt.getOpt().equals("lp")) {
                isListPrivilege = true;
                roleNameRequired = true;
            } else if (opt.getOpt().equals("conf")) {
                confPath = opt.getValue();
            }
        }
        checkRequiredParameter(roleNameRequired, roleName, OPTION_DESC_ROLE_NAME);
        checkRequiredParameter(groupNameRequired, groupName, OPTION_DESC_GROUP_NAME);
        checkRequiredParameter(privilegeStrRequired, privilegeStr, OPTION_DESC_PRIVILEGE);
    } catch (ParseException pe) {
        System.out.println(pe.getMessage());
        usage(simpleShellOptions);
        return false;
    }
    return true;
}

From source file:org.apache.tomcat.vault.VaultTool.java

/**
 * Build options for non-interactive VaultTool usage scenario.
 *
 * @return/*  w ww.j a v  a2  s . c  om*/
 */
private void initOptions() {
    options = new Options();
    options.addOption("k", KEYSTORE_PARAM, true, "Keystore URL");
    options.addOption("p", KEYSTORE_PASSWORD_PARAM, true, "Keystore password");
    options.addOption("e", ENC_DIR_PARAM, true, "Directory containing encrypted files");
    options.addOption("s", SALT_PARAM, true, "8 character salt");
    options.addOption("i", ITERATION_PARAM, true, "Iteration count");
    options.addOption("A", ALIAS_PARAM, true, "Vault keystore alias");
    options.addOption("b", VAULT_BLOCK_PARAM, true, "Vault block");
    options.addOption("a", ATTRIBUTE_PARAM, true, "Attribute name");

    OptionGroup og = new OptionGroup();
    Option x = new Option("x", SEC_ATTR_VALUE_PARAM, true,
            "Secured attribute value (such as password) to store");
    Option c = new Option("c", CHECK_SEC_ATTR_EXISTS_PARAM, false,
            "Check whether the secured attribute already exists in the vault");
    Option r = new Option("r", REMOVE_SEC_ATTR, false, "Remove the secured attribute from the vault");
    Option g = new Option("g", GENERATE_CONFIG_FILE, true, "Path for generated config file");
    Option h = new Option("h", HELP_PARAM, false, "Help");
    Option E = new Option("E", CRYPT, false, "Encrypt value using CRYPT feature");
    og.addOption(x);
    og.addOption(c);
    og.addOption(r);
    og.addOption(g);
    og.addOption(h);
    og.addOption(E);
    og.setRequired(true);
    options.addOptionGroup(og);
}

From source file:org.apache.tuscany.sca.node.equinox.launcher.NodeMain.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    OptionGroup group = new OptionGroup();
    group.addOption(new Option("dm", "domainManager", false, "Domain Manager"));
    group.addOption(new Option("nd", "nodeDaemon", false, "Node Domain"));
    options.addOptionGroup(group);// ww  w.j a  v a 2  s  . c om

    // Add options from NodeLauncher to avoid UnrecognizedOptionException
    for (Object o : NodeLauncher.getCommandLineOptions().getOptions()) {
        options.addOption((Option) o);
    }

    CommandLine cli = parser.parse(options, args);
    if (cli.hasOption("nd")) {
        NodeDaemonLauncher.main(args);
    } else if (cli.hasOption("dm")) {
        DomainManagerLauncher.main(args);
    } else {
        NodeLauncher.main(args);
    }
}

From source file:org.apache.wink.example.googledocs.CLIHelper.java

@SuppressWarnings("static-access")
public CLIHelper() {

    Option userOption = OptionBuilder.withArgName("user").hasArg()
            .withDescription("Full username. Example: user@gmail.com").isRequired(true).withLongOpt("user")
            .create(USER_OPT);//from   w  w w.  j a v  a2  s .  c o  m
    Option passwordOption = OptionBuilder.withArgName("password").isRequired(true).hasArg()
            .withDescription("Password").withLongOpt("password").create(PASSWORD_OPT);
    Option uploadFileOption = OptionBuilder.withArgName("file").isRequired(false).hasArg()
            .withDescription("Path to a file to upload").withLongOpt("upload").create(UPLOAD_FILE_OPT);
    Option listFilesOption = OptionBuilder.hasArg(false).withDescription("List files").withLongOpt("list")
            .create(LIST_OPT);
    Option deleteOption = OptionBuilder.withArgName("document id").hasArg(true)
            .withDescription("Delete document. Use --list to get a document id.").withLongOpt("delete")
            .create(DELETE_OPT);
    Option proxyHostOption = OptionBuilder.isRequired(false).withArgName("host").hasArg(true)
            .withDescription("Proxy host").withLongOpt("proxy").create(PROXY_HOST_ORT);
    Option proxyPortOption = OptionBuilder.isRequired(false).withArgName("port").hasArg(true)
            .withDescription("Proxy port").withLongOpt("port").create(PROXY_PORT_OPT);

    OptionGroup group = new OptionGroup();
    group.setRequired(true);
    group.addOption(uploadFileOption);
    group.addOption(listFilesOption);
    group.addOption(deleteOption);

    options.addOptionGroup(group);
    options.addOption(proxyHostOption);
    options.addOption(proxyPortOption);
    options.addOption(passwordOption);
    options.addOption(userOption);
}

From source file:org.apache.zookeeper.cli.DelQuotaCommand.java

public DelQuotaCommand() {
    super("delquota", "[-n|-b] path");

    OptionGroup og1 = new OptionGroup();
    og1.addOption(new Option("b", false, "bytes quota"));
    og1.addOption(new Option("n", false, "num quota"));
    options.addOptionGroup(og1);//from   w  w  w.ja va 2s.  c om
}

From source file:org.apache.zookeeper.cli.SetQuotaCommand.java

public SetQuotaCommand() {
    super("setquota", "-n|-b val path");

    OptionGroup og1 = new OptionGroup();
    og1.addOption(new Option("b", true, "bytes quota"));
    og1.addOption(new Option("n", true, "num quota"));
    og1.setRequired(true);/* w  ww  . j a v a 2 s .c o  m*/
    options.addOptionGroup(og1);
}

From source file:org.blue.star.plugins.check_ping.java

public void add_command_arguments(Options options) {
    Option p = new Option("p", "packets", true,
            "number of ICMP ECHO packets to send (Default: " + DEFAULT_MAX_PACKETS + ")");
    p.setArgName("packets");
    options.addOption(p);//w ww.  ja v a 2 s.  c  o  m
    Option w = new Option("w", "warning", true, "warning threshold pair (round trip average, % packets lost)");
    w.setArgName("<wrta>,<wpl>%");
    options.addOption(w);
    Option c = new Option("c", "critical", true,
            "critical threshold pair (round trip average, % packets lost)");
    c.setArgName("<crta>,<cpl>%");
    options.addOption(c);
    OptionGroup group = new OptionGroup();
    group.addOption(new Option("4", "use-ipv4", false, "Use IPv4 connection"));
    group.addOption(new Option("6", "use-ipv6", false, "Use IPv6 connection"));
    options.addOptionGroup(group);
    options.addOption("i", "interface", true, "Select the interface name to use.");
}