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

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

Introduction

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

Prototype

public void setRequired(boolean required) 

Source Link

Usage

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);
    options.addOptionGroup(group);//from   www .j  a va  2  s .c  o m
    //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;
}

From source file:org.ow2.proactive.authentication.crypto.CreateCredentials.java

/**
 * Entry point/*from   w  ww  . j  av  a2 s  .  c om*/
 * 
 * @see org.ow2.proactive.authentication.crypto.Credentials
 * @param args arguments, try '-h' for help
 * @throws IOException
 * @throws ParseException
 *
 */
public static void main(String[] args) throws IOException, ParseException {

    SecurityManagerConfigurator.configureSecurityManager(
            CreateCredentials.class.getResource("/all-permissions.security.policy").toString());

    Console console = System.console();
    /**
     * default values
     */
    boolean interactive = true;
    String pubKeyPath = null;
    PublicKey pubKey = null;
    String login = null;
    String pass = null;
    String keyfile = null;
    String cipher = "RSA/ECB/PKCS1Padding";
    String path = Credentials.getCredentialsPath();
    String rm = null;
    String scheduler = null;
    String url = null;

    Options options = new Options();

    Option opt = new Option("h", "help", false, "Display this help");
    opt.setRequired(false);
    options.addOption(opt);

    OptionGroup group = new OptionGroup();
    group.setRequired(false);
    opt = new Option("F", "file", true,
            "Public key path on the local filesystem [default:" + Credentials.getPubKeyPath() + "]");
    opt.setArgName("PATH");
    opt.setArgs(1);
    opt.setRequired(false);
    group.addOption(opt);

    opt = new Option("R", "rm", true, "Request the public key to the Resource Manager at URL");
    opt.setArgName("URL");
    opt.setArgs(1);
    opt.setRequired(false);
    group.addOption(opt);

    opt = new Option("S", "scheduler", true, "Request the public key to the Scheduler at URL");
    opt.setArgName("URL");
    opt.setArgs(1);
    opt.setRequired(false);
    group.addOption(opt);
    options.addOptionGroup(group);

    opt = new Option("l", "login", true,
            "Generate credentials for this specific user, will be asked interactively if not specified");
    opt.setArgName("LOGIN");
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("p", "password", true, "Use this password, will be asked interactively if not specified");
    opt.setArgName("PWD");
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("k", "keyfile", true,
            "Use specified ssh private key, asked interactively if specified without PATH, not specified otherwise.");
    opt.setArgName("PATH");
    opt.setOptionalArg(true);
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("o", "output", true,
            "Output the resulting credentials to the specified file [default:" + path + "]");
    opt.setArgName("PATH");
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("c", "cipher", true,
            "Use specified cipher parameters, need to be compatible with the specified key [default:" + cipher
                    + "]");
    opt.setArgName("PARAMS");
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(newline + "ERROR : " + e.getMessage() + newline);
        System.out.println("type -h or --help to display help screen");
        System.exit(1);
    }

    if (cmd.hasOption("help")) {
        displayHelp(options);
    }

    if (cmd.hasOption("file")) {
        pubKeyPath = cmd.getOptionValue("file");
    }
    if (cmd.hasOption("rm")) {
        rm = cmd.getOptionValue("rm");
    }
    if (cmd.hasOption("scheduler")) {
        scheduler = cmd.getOptionValue("scheduler");
    }

    if (cmd.hasOption("login")) {
        login = cmd.getOptionValue("login");
    }
    if (cmd.hasOption("password")) {
        pass = cmd.getOptionValue("password");
    }
    if (cmd.hasOption("keyfile") && cmd.getOptionValues("keyfile") != null) {
        keyfile = cmd.getOptionValue("keyfile");
    }

    if (cmd.hasOption("output")) {
        path = cmd.getOptionValue("output");
    }
    if (cmd.hasOption("cipher")) {
        cipher = cmd.getOptionValue("cipher");
    }

    int acc = 0;
    if (pubKeyPath != null) {
        acc++;
    }
    if (scheduler != null) {
        url = Connection.normalize(scheduler) + "SCHEDULER";
        acc++;

    }
    if (rm != null) {
        url = Connection.normalize(rm) + "RMAUTHENTICATION";
        acc++;
    }
    if (acc > 1) {
        System.out.println("--rm, --scheduler and --file arguments cannot be combined.");
        System.out.println("try -h for help.");
        System.exit(1);
    }

    if (url != null) {
        try {
            Connection<AuthenticationImpl> conn = new Connection<AuthenticationImpl>(AuthenticationImpl.class) {
                public Logger getLogger() {
                    return Logger.getLogger("pa.scheduler.credentials");
                }
            };
            AuthenticationImpl auth = conn.connect(url);
            pubKey = auth.getPublicKey();
        } catch (Exception e) {
            System.err.println("ERROR : Could not retrieve public key from '" + url + "'");
            e.printStackTrace();
            System.exit(3);
        }
        System.out.println("Successfully obtained public key from " + url + newline);
    } else if (pubKeyPath != null) {
        try {
            pubKey = Credentials.getPublicKey(pubKeyPath);
        } catch (KeyException e) {
            System.err
                    .println("ERROR : Could not retrieve public key from '" + pubKeyPath + "' (no such file)");
            System.exit(4);
        }
    } else {
        System.out.println("No public key specified, attempting to retrieve it from default location.");
        pubKeyPath = Credentials.getPubKeyPath();
        try {
            pubKey = Credentials.getPublicKey(pubKeyPath);
        } catch (KeyException e) {
            System.err
                    .println("ERROR : Could not retrieve public key from '" + pubKeyPath + "' (no such file)");
            System.exit(5);
        }
    }

    if (login != null && pass != null
            && (!cmd.hasOption("keyfile") || cmd.getOptionValues("keyfile") != null)) {
        System.out.println("Running in non-interactive mode." + newline);
        interactive = false;
    } else {
        System.out.println("Running in interactive mode.");
    }

    if (interactive) {
        System.out.println("Please enter Scheduler credentials,");
        System.out.println("they will be stored encrypted on disk for future logins." + newline);
        System.out.print("login: ");
        if (login == null) {
            login = console.readLine();
        } else {
            System.out.println(login);
        }
        System.out.print("password: ");
        if (pass == null) {
            pass = new String(console.readPassword());
        } else {
            System.out.println("*******");
        }
        System.out.print("keyfile: ");
        if (!cmd.hasOption("keyfile")) {
            System.out.println("no key file specified");
        } else if (cmd.hasOption("keyfile") && cmd.getOptionValues("keyfile") != null) {
            System.out.println(keyfile);
        } else {
            keyfile = console.readLine();
        }
    }

    try {
        CredData credData;
        if (keyfile != null && keyfile.length() > 0) {
            byte[] keyfileContent = FileToBytesConverter.convertFileToByteArray(new File(keyfile));
            credData = new CredData(CredData.parseLogin(login), CredData.parseDomain(login), pass,
                    keyfileContent);
        } else {
            System.out.println("--> Ignoring keyfile, credential does not contain SSH key");
            credData = new CredData(CredData.parseLogin(login), CredData.parseDomain(login), pass);
        }
        Credentials cred = Credentials.createCredentials(credData, pubKey, cipher);
        cred.writeToDisk(path);
    } catch (FileNotFoundException e) {
        System.err.println("ERROR : Could not retrieve ssh private key from '" + keyfile + "' (no such file)");
        System.exit(6);
    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(7);
    }

    System.out.println("Successfully stored encrypted credentials on disk at :");
    System.out.println("\t" + path);

    System.exit(0);
}

From source file:org.ow2.proactive.scheduler.authentication.ManageUsers.java

/**
 * Build the command line options and parse
 *///from   w  w w  . jav  a 2s. c  o  m
private static CommandLine getCommandLine(String[] args, String loginFilePath, String groupFilePath,
        Options options) throws ManageUsersException {
    Option opt = new Option(HELP_OPTION, HELP_OPTION_NAME, false, "Display this help");
    opt.setRequired(false);
    options.addOption(opt);
    OptionGroup optionGroup = new OptionGroup();
    optionGroup.setRequired(false);

    opt = new Option(CREATE_OPTION, CREATE_OPTION_NAME, true, "Action to create a user");
    opt.setArgName(CREATE_OPTION_NAME.toUpperCase());
    opt.setArgs(0);
    opt.setRequired(false);
    optionGroup.addOption(opt);

    opt = new Option(UPDATE_OPTION, UPDATE_OPTION_NAME, true,
            "Action to update an existing user. Updating a user means to change the user's password or group membership.");
    opt.setArgName(UPDATE_OPTION_NAME.toUpperCase());
    opt.setArgs(0);
    opt.setRequired(false);
    optionGroup.addOption(opt);

    opt = new Option(DELETE_OPTION, DELETE_OPTION_NAME, true, "Action to delete an existing user");
    opt.setArgName(DELETE_OPTION_NAME.toUpperCase());
    opt.setArgs(0);
    opt.setRequired(false);
    optionGroup.addOption(opt);
    options.addOptionGroup(optionGroup);

    opt = new Option(LOGIN_OPTION, LOGIN_OPTION_NAME, true,
            "Generate credentials for this specific user, will be asked interactively if not specified");
    opt.setArgName(LOGIN_OPTION_NAME.toUpperCase());
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(PWD_OPTION, PWD_OPTION_NAME, true,
            "Password of the user, if the user is created or updated, will be asked interactively if not specified");
    opt.setArgName(PWD_OPTION_NAME.toUpperCase());
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(GROUPS_OPTION, GROUPS_OPTION_NAME, true,
            "A comma-separated list of groups the user must be member of. Can be used when the user is created or updated");
    opt.setArgName(GROUPS_OPTION_NAME.toUpperCase());
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    optionGroup.setRequired(false);
    opt = new Option(KEYFILE_OPTION, KEYFILE_OPTION_NAME, true,
            "Public key path on the local filesystem [default:" + getPublicKeyFilePath() + "]");
    opt.setArgName(KEYFILE_OPTION_NAME.toUpperCase());
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(LOGINFILE_OPTION, LOGINFILE_OPTION_NAME, true,
            "Path to the login file in use [default:" + loginFilePath + "]");
    opt.setArgName(LOGINFILE_OPTION_NAME.toUpperCase());
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(GROUPFILE_OPTION, GROUPFILE_OPTION_NAME, true,
            "Path to the group file in use [default:" + groupFilePath + "]");
    opt.setArgName(GROUPFILE_OPTION_NAME.toUpperCase());
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(SOURCE_LOGINFILE_OPTION, SOURCE_LOGINFILE_OPTION_NAME, true,
            "Path to a source login file, used for bulk creation or bulk update. The source login file must contain clear text passwords in the format username:password");
    opt.setArgName(SOURCE_LOGINFILE_OPTION_NAME.toUpperCase());
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option(SOURCE_GROUPFILE_OPTION, SOURCE_GROUPFILE_OPTION_NAME, true,
            "Path to a source group file, used for bulk creation or bulk update. The source group file must contain group assignements in the format username:group");
    opt.setArgName(SOURCE_GROUPFILE_OPTION_NAME.toUpperCase());
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        exitWithErrorMessage(newline + e.getMessage() + newline, "type -h or --help to display help screen",
                null);
    }
    return cmd;
}

From source file:org.shaf.core.process.cmd.CommandOptionHandler.java

/**
 * Generates a command line option group for the specified
 * {@code GroupOptionInfo}./* w  ww  .  j a  va  2 s . com*/
 * 
 * @param groupOptionInfo
 *            the specified {@code GroupOptionInfo} .
 * @return the generated command line option group.
 */
private static OptionGroup generate(final GroupOptionInfo groupOptionInfo) {
    OptionGroup group = new OptionGroup();

    for (SingleOptionInfo info : groupOptionInfo) {
        group.addOption(generate(info));
    }
    group.setRequired(groupOptionInfo.isRequired());

    return group;
}

From source file:org.syphr.mythtv.apps.commander.CommanderOption.java

public static Options getOptions() {
    Options options = new Options();

    options.addOption(HELP.getOption());
    options.addOption(HOST.getOption());
    options.addOption(PORT.getOption());
    options.addOption(TIMEOUT.getOption());
    options.addOption(COMMANDS.getOption());

    OptionGroup typeGroup = new OptionGroup();
    typeGroup.setRequired(true);
    typeGroup.addOption(FRONTEND.getOption());
    typeGroup.addOption(BACKEND.getOption());
    options.addOptionGroup(typeGroup);//  www  .j a  v a 2  s  .  c  om

    return options;
}

From source file:org.tolven.appserverproperties.AppServerPropertiesPlugin.java

private Options getCommandOptions() {
    Options cmdLineOptions = new Options();
    OptionGroup optionGroup = new OptionGroup();
    Option displayOption = new Option(CMD_LINE_DISPLAY_OPTION, CMD_LINE_DISPLAY_OPTION, false,
            "\"display server properties\"");
    optionGroup.addOption(displayOption);
    Option importOption = new Option(CMD_LINE_LOAD_OPTION, CMD_LINE_LOAD_OPTION, false,
            "\"load server properties\"");
    optionGroup.addOption(importOption);
    Option changeOption = new Option(CMD_LINE_SET_OPTION, CMD_LINE_SET_OPTION, true,
            "\"set a server property e.g. -set someKey someValue\"");
    changeOption.setArgs(2);/* ww  w. j  a v a  2 s.c  o m*/
    optionGroup.addOption(changeOption);
    Option removeOption = new Option(CMD_LINE_REMOVE_OPTION, CMD_LINE_REMOVE_OPTION, true,
            "\"remove a server property e.g. -remove someKey\"");
    optionGroup.addOption(removeOption);
    //Option guiOption = new Option(CMD_LINE_GUI_OPTION, CMD_LINE_GUI_OPTION, false, "\"start the password recovery gui\"");
    //optionGroup.addOption(guiOption);
    optionGroup.setRequired(true);
    cmdLineOptions.addOptionGroup(optionGroup);
    return cmdLineOptions;
}

From source file:org.tolven.developmentmgr.DevelopmentMgr.java

private Options getCommandOptions() {
    Options cmdLineOptions = new Options();
    OptionGroup optionGroup = new OptionGroup();
    optionGroup.setRequired(true);
    Option devLibOption = new Option(CMD_LINE_DEVLIB_OPTION, CMD_LINE_DEVLIB_OPTION, false,
            "\"deploy development library\"");
    optionGroup.addOption(devLibOption);
    cmdLineOptions.addOptionGroup(optionGroup);
    return cmdLineOptions;
}

From source file:org.tolven.glassfishmgr.GlassFishMgrPlugin.java

private Options getCommandOptions() {
    Options cmdLineOptions = new Options();
    OptionGroup optionGroup = new OptionGroup();
    Option testAdminAppServerOption = new Option(CMD_LINE_TEST_ADMIN_APPSERVER_OPTION,
            CMD_LINE_TEST_ADMIN_APPSERVER_OPTION, false, "\"test admin to appserver connection\"");
    optionGroup.addOption(testAdminAppServerOption);
    Option guiOption = new Option(CMD_LINE_GUI_OPTION, CMD_LINE_GUI_OPTION, false,
            "\"start the glassfish manager gui\"");
    optionGroup.addOption(guiOption);/*from   ww  w .  j  a v  a 2 s.c  o m*/
    optionGroup.setRequired(true);
    cmdLineOptions.addOptionGroup(optionGroup);
    return cmdLineOptions;
}

From source file:org.tolven.ldapmgr.LDAPMgrPlugin.java

private Options getCommandOptions() {
    Options cmdLineOptions = new Options();
    OptionGroup optionGroup = new OptionGroup();
    Option testRootDNLDAPOption = new Option(CMD_LINE_TEST_ROOTDN_LDAP_OPTION, CMD_LINE_TEST_ROOTDN_LDAP_OPTION,
            false, "\"test rootDN to LDAP connection\"");
    optionGroup.addOption(testRootDNLDAPOption);
    Option testAdminLDAPOption = new Option(CMD_LINE_TEST_ADMIN_LDAP_OPTION, CMD_LINE_TEST_ADMIN_LDAP_OPTION,
            false, "\"test admin to LDAP connection\"");
    optionGroup.addOption(testAdminLDAPOption);
    Option testAppServerLDAPOption = new Option(CMD_LINE_TEST_APPSERVER_LDAP_OPTION,
            CMD_LINE_TEST_APPSERVER_LDAP_OPTION, false, "\"simulate appserver to LDAP connection\"");
    optionGroup.addOption(testAppServerLDAPOption);
    Option updateSchemasOption = new Option(CMD_LINE_UPDATE_SCHEMAS_OPTION, CMD_LINE_UPDATE_SCHEMAS_OPTION,
            false, "\"update schemas\"");
    optionGroup.addOption(updateSchemasOption);
    Option guiOption = new Option(CMD_LINE_GUI_OPTION, CMD_LINE_GUI_OPTION, false,
            "\"start the LDAP manager gui\"");
    optionGroup.addOption(guiOption);/*www  .j ava2 s  .  c o  m*/
    optionGroup.setRequired(true);
    cmdLineOptions.addOptionGroup(optionGroup);
    return cmdLineOptions;
}

From source file:org.tolven.legacypostgresql.db.LegacyPostgresqlDBPlugin.java

private Options getCommandOptions() {
    Options cmdLineOptions = new Options();
    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(new Option(CMD_SCHEMAS, CMD_SCHEMAS, false, "\"schemas\""));
    optionGroup.addOption(new Option(CMD_INDEXES, CMD_INDEXES, false, "\"indexes\""));
    optionGroup.setRequired(true);
    cmdLineOptions.addOptionGroup(optionGroup);
    Option dbUrlOption = new Option(CMD_DBURL, CMD_DBURL, true, "\"dbUrl\"");
    dbUrlOption.setRequired(true);/*from w w w. ja v  a  2s . c om*/
    cmdLineOptions.addOption(dbUrlOption);
    Option driverClassOption = new Option(CMD_DRIVERCLASS, CMD_DRIVERCLASS, true, "\"driverClass\"");
    driverClassOption.setRequired(true);
    cmdLineOptions.addOption(driverClassOption);
    Option userOption = new Option(CMD_USER, CMD_USER, true, "\"user\"");
    userOption.setRequired(true);
    cmdLineOptions.addOption(userOption);
    Option passwordOption = new Option(CMD_PASSWORD, CMD_PASSWORD, true, "\"password\"");
    passwordOption.setRequired(true);
    cmdLineOptions.addOption(passwordOption);
    Option driverClasspathOption = new Option(CMD_DRIVERCLASSPATH, CMD_DRIVERCLASSPATH, true,
            "\"driverClasspath\"");
    cmdLineOptions.addOption(driverClasspathOption);
    return cmdLineOptions;
}