Example usage for org.apache.commons.cli OptionBuilder withDescription

List of usage examples for org.apache.commons.cli OptionBuilder withDescription

Introduction

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

Prototype

public static OptionBuilder withDescription(String newDescription) 

Source Link

Document

The next Option created will have the specified description

Usage

From source file:com.google.code.uclassify.client.examples.TrainExample.java

/**
 * Build command line options object./*w w  w.ja va 2  s  .c  o  m*/
 * 
 * @return the options
 */
private static Options buildOptions() {

    Options opts = new Options();

    String helpMsg = "Print this message.";
    Option help = new Option(HELP_OPTION, helpMsg);
    opts.addOption(help);

    String consumerKeyMsg = "You API Write Key.";
    OptionBuilder.withArgName("readKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(WRITE_KEY);
    opts.addOption(consumerKey);

    String idMsg = "Classifier Name";
    OptionBuilder.withArgName("classifier");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(idMsg);
    Option id = OptionBuilder.create(CLASSIFIER);
    opts.addOption(id);

    String urlMsg = "Text to be classified.";
    OptionBuilder.withArgName("text");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(urlMsg);
    Option url = OptionBuilder.create(TEXT);
    opts.addOption(url);

    return opts;
}

From source file:edu.harvard.med.iccbl.screensaver.io.AdminEmailApplication.java

@SuppressWarnings("static-access")
public AdminEmailApplication(String[] cmdLineArgs) {
    super(cmdLineArgs);

    addCommandLineOption(OptionBuilder.hasArg().withArgName(EMAIL_RECIPIENT_LIST_OPTION[ARG_INDEX])
            .withDescription(EMAIL_RECIPIENT_LIST_OPTION[DESCRIPTION_INDEX])
            .withLongOpt(EMAIL_RECIPIENT_LIST_OPTION[LONG_OPTION_INDEX])
            .create(EMAIL_RECIPIENT_LIST_OPTION[SHORT_OPTION_INDEX]));
    addCommandLineOption(OptionBuilder.withDescription(NO_NOTIFY_OPTION[DESCRIPTION_INDEX])
            .withLongOpt(NO_NOTIFY_OPTION[LONG_OPTION_INDEX]).create(NO_NOTIFY_OPTION[SHORT_OPTION_INDEX]));
    addCommandLineOption(OptionBuilder.withDescription(TEST_EMAIL_ONLY[DESCRIPTION_INDEX])
            .withLongOpt(TEST_EMAIL_ONLY[LONG_OPTION_INDEX]).create(TEST_EMAIL_ONLY[SHORT_OPTION_INDEX]));
    addCommandLineOption(OptionBuilder.withDescription(EMAIL_DSL_ADMINS_ONLY[DESCRIPTION_INDEX])
            .withLongOpt(EMAIL_DSL_ADMINS_ONLY[LONG_OPTION_INDEX])
            .create(EMAIL_DSL_ADMINS_ONLY[SHORT_OPTION_INDEX]));
}

From source file:com.google.code.linkedinapi.client.examples.PostNetworkUpdateExample.java

/**
  * Build command line options object./*  ww  w  . j  av a 2 s  .c  om*/
  */
private static Options buildOptions() {

    Options opts = new Options();

    String helpMsg = "Print this message.";
    Option help = new Option(HELP_OPTION, helpMsg);
    opts.addOption(help);

    String consumerKeyMsg = "You API Consumer Key.";
    OptionBuilder.withArgName("consumerKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(CONSUMER_KEY_OPTION);
    opts.addOption(consumerKey);

    String consumerSecretMsg = "You API Consumer Secret.";
    OptionBuilder.withArgName("consumerSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerSecretMsg);
    Option consumerSecret = OptionBuilder.create(CONSUMER_SECRET_OPTION);
    opts.addOption(consumerSecret);

    String accessTokenMsg = "You OAuth Access Token.";
    OptionBuilder.withArgName("accessToken");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(accessTokenMsg);
    Option accessToken = OptionBuilder.create(ACCESS_TOKEN_OPTION);
    opts.addOption(accessToken);

    String tokenSecretMsg = "You OAuth Access Token Secret.";
    OptionBuilder.withArgName("accessTokenSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(tokenSecretMsg);
    Option accessTokenSecret = OptionBuilder.create(ACCESS_TOKEN_SECRET_OPTION);
    opts.addOption(accessTokenSecret);

    String updateMsg = "Text of the update.";
    OptionBuilder.withArgName("update");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(updateMsg);
    Option update = OptionBuilder.create(UPDATE_TEXT_OPTION);
    opts.addOption(update);

    return opts;
}

From source file:it.crs4.seal.common.SealToolParser.java

/**
 * Construct a SealToolParser instance./*from  w  w  w. j  a v a 2 s  .  com*/
 *
 * The instance is set to read the properties in configuration file's section sectionName,
 * in addition to the default section.  Properties set on the command line will override
 * the file's settings.
 *
 * @param configSection Name of section of configuration to load, in addition to DEFAULT.
 * If null, only DEFAULT is loaded
 * @param toolName Name used in the help message
 */
@SuppressWarnings("static") // for OptionBuilder
public SealToolParser(String configSection, String toolName) {
    this.toolName = toolName;

    options = new Options(); // empty
    opt_nReduceTasks = OptionBuilder.withDescription("Number of reduce tasks to use.").hasArg()
            .withArgName("INT").withLongOpt("num-reducers").create("r");
    options.addOption(opt_nReduceTasks);

    opt_configFileOverride = OptionBuilder
            .withDescription("Override default Seal config file (" + DefaultConfigFile + ")").hasArg()
            .withArgName("FILE").withLongOpt("seal-config").create("sc");
    options.addOption(opt_configFileOverride);

    opt_inputFormat = OptionBuilder.withDescription(INPUT_FORMAT_DESC).hasArg().withArgName("FORMAT")
            .withLongOpt("input-format").create("if");
    options.addOption(opt_inputFormat);

    opt_outputFormat = OptionBuilder.withDescription(OUTPUT_FORMAT_DESC).hasArg().withArgName("FORMAT")
            .withLongOpt("output-format").create("of");
    options.addOption(opt_outputFormat);

    opt_compressOutput = OptionBuilder
            .withDescription("Compress output files with CODEC (one of gzip, bzip2, snappy, auto)").hasArg()
            .withArgName("CODEC").withLongOpt("compress-output").create("oc");
    options.addOption(opt_compressOutput);

    nReduceTasks = null;
    inputs = new ArrayList<Path>(10);
    outputDir = null;
    this.configSection = (configSection == null) ? "" : configSection;
    minReduceTasks = DEFAULT_MIN_REDUCE_TASKS;
    myconf = null;
    nReduceTasksPerNode = DEFAULT_REDUCE_TASKS_PER_NODE;
}

From source file:com.haulmont.cuba.core.sys.utils.DbUpdaterUtil.java

@SuppressWarnings("AccessStaticViaInstance")
public void execute(String[] args) {
    Options cliOptions = new Options();

    Option dbConnectionOption = OptionBuilder.withArgName("connectionString").hasArgs()
            .withDescription("JDBC Database URL").isRequired().create("dbUrl");

    Option dbUserOption = OptionBuilder.withArgName("userName").hasArgs().withDescription("Database user")
            .isRequired().create("dbUser");

    Option dbPasswordOption = OptionBuilder.withArgName("password").hasArgs()
            .withDescription("Database password").isRequired().create("dbPassword");

    Option dbDriverClassOption = OptionBuilder.withArgName("driverClassName").hasArgs()
            .withDescription("JDBC driver class name").create("dbDriver");

    Option dbDirOption = OptionBuilder.withArgName("filePath").hasArgs()
            .withDescription("Database scripts directory").isRequired().create("scriptsDir");

    Option dbTypeOption = OptionBuilder.withArgName("dbType").hasArgs()
            .withDescription("DBMS type: postgres|mssql|oracle|etc").isRequired().create("dbType");

    Option dbVersionOption = OptionBuilder.withArgName("dbVersion").hasArgs()
            .withDescription("DBMS version: 2012|etc").create("dbVersion");

    Option dbExecuteGroovyOption = OptionBuilder.withArgName("executeGroovy").hasArgs()
            .withDescription("Ignoring Groovy scripts").create("executeGroovy");

    Option showUpdatesOption = OptionBuilder.withDescription("Print update scripts").create("check");

    Option applyUpdatesOption = OptionBuilder.withDescription("Update database").create("update");

    Option createDbOption = OptionBuilder.withDescription("Create database").create("create");

    cliOptions.addOption("help", false, "Print help");
    cliOptions.addOption(dbConnectionOption);
    cliOptions.addOption(dbUserOption);/*ww w . j a v  a 2s  .c om*/
    cliOptions.addOption(dbPasswordOption);
    cliOptions.addOption(dbDirOption);
    cliOptions.addOption(dbTypeOption);
    cliOptions.addOption(dbVersionOption);
    cliOptions.addOption(dbExecuteGroovyOption);
    cliOptions.addOption(showUpdatesOption);
    cliOptions.addOption(applyUpdatesOption);
    cliOptions.addOption(createDbOption);

    CommandLineParser parser = new PosixParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;
    try {
        cmd = parser.parse(cliOptions, args);
    } catch (ParseException exp) {
        formatter.printHelp("dbupdate", cliOptions);
        return;
    }

    if (cmd.hasOption("help") || (!cmd.hasOption(showUpdatesOption.getOpt()))
            && !cmd.hasOption(applyUpdatesOption.getOpt()) && !cmd.hasOption(createDbOption.getOpt()))
        formatter.printHelp("dbupdate", cliOptions);
    else {
        this.dbScriptsDirectory = cmd.getOptionValue(dbDirOption.getOpt());
        File directory = new File(dbScriptsDirectory);
        if (!directory.exists()) {
            log.error("Not found db update directory");
            return;
        }

        dbmsType = cmd.getOptionValue(dbTypeOption.getOpt());
        dbmsVersion = StringUtils.trimToEmpty(cmd.getOptionValue(dbVersionOption.getOpt()));

        AppContext.Internals.setAppComponents(new AppComponents("core"));

        AppContext.setProperty("cuba.dbmsType", dbmsType);
        AppContext.setProperty("cuba.dbmsVersion", dbmsVersion);

        String dbDriver;
        if (!cmd.hasOption(dbDriverClassOption.getOpt())) {
            switch (dbmsType) {
            case "postgres":
                dbDriver = "org.postgresql.Driver";
                break;
            case "mssql":
                if (MS_SQL_2005.equals(dbmsVersion)) {
                    dbDriver = "net.sourceforge.jtds.jdbc.Driver";
                } else {
                    dbDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
                }
                break;
            case "oracle":
                dbDriver = "oracle.jdbc.OracleDriver";
                break;
            default:
                log.error(
                        "Unable to determine driver class name by DBMS type. Please provide driverClassName option");
                return;
            }
        } else {
            dbDriver = cmd.getOptionValue(dbDriverClassOption.getOpt());
        }

        try {
            Class.forName(dbDriver);
        } catch (ClassNotFoundException e) {
            log.error("Unable to load driver class " + dbDriver);
            return;
        }

        String connectionStringParam = cmd.getOptionValue(dbConnectionOption.getOpt());
        try {
            this.dataSource = new SingleConnectionDataSource(connectionStringParam,
                    cmd.getOptionValue(dbUserOption.getOpt()), cmd.getOptionValue(dbPasswordOption.getOpt()));
        } catch (SQLException e) {
            log.error("Unable to connect to db: " + connectionStringParam);
            return;
        }

        if (cmd.hasOption(createDbOption.getOpt())) {
            // create database from init scripts
            StringBuilder availableScripts = new StringBuilder();
            for (ScriptResource initScript : getInitScripts()) {
                availableScripts.append("\t").append(getScriptName(initScript)).append("\n");
            }
            log.info("Available create scripts: \n" + availableScripts);
            log.info(String.format("Do you want to create database %s ? [y/n]", connectionStringParam));
            Scanner scanner = new Scanner(new InputStreamReader(System.in, StandardCharsets.UTF_8));
            if ("y".equals(scanner.next())) {
                doInit();
            }
        } else {
            boolean updatesAvailable = false;
            try {
                List<String> scripts;

                executeGroovy = !(cmd.hasOption(dbExecuteGroovyOption.getOpt())
                        && cmd.getOptionValue(dbExecuteGroovyOption.getOpt()).equals("false"));

                scripts = findUpdateDatabaseScripts();

                if (!scripts.isEmpty()) {
                    StringBuilder availableScripts = new StringBuilder();
                    for (String script : scripts) {
                        availableScripts.append("\t").append(script).append("\n");
                    }
                    log.info("Available updates:\n" + availableScripts);
                    updatesAvailable = true;
                } else
                    log.info("No available updates found for database");
            } catch (DbInitializationException e) {
                log.warn("Database not initialized");
                return;
            }

            if (updatesAvailable && cmd.hasOption(applyUpdatesOption.getOpt())) {
                log.info(String.format("Do you want to apply updates to %s ? [y/n]", connectionStringParam));
                Scanner scanner = new Scanner(new InputStreamReader(System.in, StandardCharsets.UTF_8));
                if ("y".equals(scanner.next())) {
                    doUpdate();
                }
            }
        }
    }
}

From source file:jurbano.melodyshape.ui.ConsoleUIObserver.java

/**
 * Constructs a new {@code ConsoleUIObserver} according to some command line
 * arguments./*from  w ww .  j  ava2s .c o m*/
 * 
 * @param args
 *            the command line arguments to configure the algorithm.
 */
@SuppressWarnings("static-access")
public ConsoleUIObserver(String[] args) {
    this.args = args;

    this.qOpt = null;
    this.cOpt = null;
    this.aOpt = null;
    this.lOpt = false;
    this.hOpt = false;
    this.tOpt = Runtime.getRuntime().availableProcessors();
    this.kOpt = Integer.MAX_VALUE;
    this.vOpt = 0;

    this.options = new Options();
    // required arguments
    this.options.addOption(OptionBuilder.isRequired().hasArg().withArgName("file/dir")
            .withDescription("path to the query melody or melodies.").create("q"));
    this.options.addOption(OptionBuilder.isRequired().hasArg().withArgName("dir")
            .withDescription("path to the collection of documents.").create("c"));
    this.options.addOption(OptionBuilder.isRequired().hasArg().withArgName("name")
            .withDescription("algorithm to run:" + "\n- 2010-domain, 2010-pitchderiv, 2010-shape"
                    + "\n- 2011-shape, 2011-pitch, 2011-time"
                    + "\n- 2012-shapeh, 2012-shapel, 2012-shapeg, 2012-time, 2012-shapetime"
                    + "\n- 2013-shapeh, 2013-time, 2013-shapetime"
                    + "\n- 2014-shapeh, 2014-time, 2014-shapetime"
                    + "\n- 2015-shapeh, 2015-time, 2015-shapetime")
            .create("a"));
    // optional arguments
    this.options.addOption(OptionBuilder
            .withDescription("show results in a single line (omits similarity scores).").create("l"));
    this.options.addOption(OptionBuilder.hasArg().withArgName("num")
            .withDescription("run a fixed number of threads.").create("t"));
    this.options.addOption(OptionBuilder.hasArg().withArgName("cutoff")
            .withDescription("number of documents to retrieve.").create("k"));
    this.options.addOption(OptionBuilder.withDescription("verbose, to stderr.").create("v"));
    this.options.addOption(OptionBuilder.withDescription("verbose a lot, to stderr.").create("vv"));
    this.options.addOption(OptionBuilder.withDescription("show this help message.").create("h"));
    this.options.addOption(OptionBuilder.withDescription("run with graphical user interface.").create("gui"));
}

From source file:it.polimi.tower4clouds.rules.batch.BatchTool.java

@SuppressWarnings("static-access")
private static Options buildOptions() {
    Options options = new Options();
    options.addOption(OptionBuilder.withDescription("print this message").withLongOpt("help").create("h"));
    options.addOption(OptionBuilder.withArgName("file").hasArg()
            .withDescription("validate monitoring rules in the given file").withLongOpt("validate-rules")
            .create("v"));
    options.addOption(OptionBuilder.withArgName("file").hasArg()
            .withDescription("validate qos constraints in the given file").withLongOpt("validate-constraints")
            .create("c"));
    options.addOption(OptionBuilder.withArgName("file").hasArg().withLongOpt("make-rules")
            .withDescription("make monitoring rules from qos constraints in the given file").create("r"));
    return options;
}

From source file:com.google.code.linkedinapi.client.examples.MessagingApiExample.java

/**
  * Build command line options object.//from ww  w .ja va  2  s. c  o  m
  */
private static Options buildOptions() {

    Options opts = new Options();

    String helpMsg = "Print this message.";
    Option help = new Option(HELP_OPTION, helpMsg);
    opts.addOption(help);

    String consumerKeyMsg = "You API Consumer Key.";
    OptionBuilder.withArgName("consumerKey");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerKeyMsg);
    Option consumerKey = OptionBuilder.create(CONSUMER_KEY_OPTION);
    opts.addOption(consumerKey);

    String consumerSecretMsg = "You API Consumer Secret.";
    OptionBuilder.withArgName("consumerSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(consumerSecretMsg);
    Option consumerSecret = OptionBuilder.create(CONSUMER_SECRET_OPTION);
    opts.addOption(consumerSecret);

    String accessTokenMsg = "You OAuth Access Token.";
    OptionBuilder.withArgName("accessToken");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(accessTokenMsg);
    Option accessToken = OptionBuilder.create(ACCESS_TOKEN_OPTION);
    opts.addOption(accessToken);

    String tokenSecretMsg = "You OAuth Access Token Secret.";
    OptionBuilder.withArgName("accessTokenSecret");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(tokenSecretMsg);
    Option accessTokenSecret = OptionBuilder.create(ACCESS_TOKEN_SECRET_OPTION);
    opts.addOption(accessTokenSecret);

    String idMsg = "IDs of the users to whom a message is to be sent (separated by comma).";
    OptionBuilder.withArgName("ids");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(idMsg);
    Option id = OptionBuilder.create(ID_OPTION);
    opts.addOption(id);

    String subjectMsg = "Subject of the message.";
    OptionBuilder.withArgName("subject");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(subjectMsg);
    Option subject = OptionBuilder.create(SUBJECT_OPTION);
    opts.addOption(subject);

    String messageMsg = "Content of the message.";
    OptionBuilder.withArgName("message");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(messageMsg);
    Option message = OptionBuilder.create(MESSAGE_OPTION);
    opts.addOption(message);

    return opts;
}

From source file:cn.edu.pku.cbi.mosaichunter.MosaicHunter.java

private static boolean loadConfiguration(String[] args, String configFile) throws Exception {
    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg();//from  w  w w. j  a  va2 s.  c om
    OptionBuilder.withDescription("config file");
    OptionBuilder.withLongOpt("config");
    Option configFileOption = OptionBuilder.create("C");

    OptionBuilder.withArgName("property=value");
    OptionBuilder.hasArgs(2);
    OptionBuilder.withValueSeparator();
    OptionBuilder.withDescription("properties that overrides the ones in config file");
    OptionBuilder.withLongOpt("properties");
    Option propertiesOption = OptionBuilder.create("P");

    Options options = new Options();
    options.addOption(configFileOption);
    options.addOption(propertiesOption);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException pe) {
        System.out.println(pe.getMessage());
        return false;
    }

    InputStream in = null;

    if (configFile == null || configFile.trim().isEmpty()) {
        configFile = cmd.getOptionValue("C");
        if (configFile != null && new File(configFile).isFile()) {
            in = new FileInputStream(configFile);
        }
    } else {
        in = MosaicHunter.class.getClassLoader().getResourceAsStream(configFile);
    }
    if (in != null) {
        try {
            ConfigManager.getInstance().loadProperties(in);
        } catch (IOException ioe) {
            System.out.println("invalid config file: " + configFile);
            return false;
        } finally {
            in.close();
        }
    }

    Properties properties = cmd.getOptionProperties("P");
    if (properties != null) {
        ConfigManager.getInstance().putAll(properties);
    }

    return !ConfigManager.getInstance().getProperties().isEmpty();
}

From source file:de.weltraumschaf.jebnf.cli.CliOptions.java

/**
 * Configures the {@link #options}.//w w w .j av a  2 s .  c o m
 */
public CliOptions() {
    options = new Options();
    // w/ argument
    options.addOption(
            OptionBuilder.withDescription("EBNF syntax file to parse. Required option, unless you use the IDE.")
                    .withArgName("file").hasArg().create(OptionsParser.OPT_SYNTAX));
    options.addOption(
            OptionBuilder.withDescription("Output file name. If omitted output will be print to STDOUT.")
                    .withArgName("file").hasArg().create(OptionsParser.OPT_OUTPUT));
    options.addOption(OptionBuilder.withDescription("Output format: tree, xml, jpg, gif, or png.")
            .withArgName("format").hasArg().create(OptionsParser.OPT_FORMAT));
    // w/o argument
    options.addOption(OptionsParser.OPT_DEBUG, false, "Enables debug output.");
    options.addOption(OptionsParser.OPT_HELP, false, "This help.");
    options.addOption(OptionsParser.OPT_VERSION, false, "Show version information.");
    options.addOption(OptionsParser.OPT_IDE, OptionsParser.OPT_IDE_LONG, false, "Starts the GUI IDE.");
}