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:net.bpelunit.framework.ui.command.BPELUnitCommandLineRunner.java

@SuppressWarnings("static-access")
private final void createOptions() {
    options = new Options();

    options.addOption(PARAMETER_VERBOSE, false,
            Messages.getString("BPELUnitCommandLineRunner.PARAMTER_DESCRIPTION_VERBOSE")); //$NON-NLS-1$
    options.addOption(OptionBuilder
            .withDescription(Messages.getString("BPELUnitCommandLineRunner.PARAMETER_DESCRIPTION_XMLFILE")) //$NON-NLS-1$
            .hasArg().withArgName("FILE").create(PARAMETER_XMLFILE));
    options.addOption(OptionBuilder//from w  w w .j a  v a  2  s. co  m
            .withDescription(Messages.getString("BPELUnitCommandLineRunner.PARAMETER_DESCRIPTION_LOGFILE")) //$NON-NLS-1$
            .hasArg().withArgName("FILE").create(PARAMETER_LOGFILE));
    options.addOption(OptionBuilder
            .withDescription(Messages.getString("BPELUnitCommandLineRunner.PARAMETER_DESCRIPTION_COVERAGEFILE")) //$NON-NLS-1$
            .hasArg().withArgName("FILE").create(PARAMETER_COVERAGEFILE));
    options.addOption(OptionBuilder
            .withDescription(
                    Messages.getString("BPELUnitCommandLineRunner.PARAMTER_DESCRIPTION_DETAILEDCOVERAGEFILE")) //$NON-NLS-1$
            .hasArg().withArgName("FILE").create(PARAMETER_DETAILEDCOVERAGEFILE));
}

From source file:ivory.app.PreprocessTrecForeign.java

@SuppressWarnings("static-access")
private Configuration parseArgs(String[] args) {
    Configuration conf = getConf();
    options = new Options();
    options.addOption(OptionBuilder.withDescription("tokenizer class").withArgName("class").hasArg()
            .isRequired().create(TOKENIZER_CLASS_OPTION));
    options.addOption(OptionBuilder.withDescription("path to tokenizer model file/directory")
            .withArgName("path").hasArg().create(TOKENIZER_MODEL_OPTION));
    options.addOption(OptionBuilder.withDescription("path to index directory").withArgName("path").hasArg()
            .isRequired().isRequired().create(INDEX_PATH_OPTION));
    options.addOption(OptionBuilder.withDescription("path to XML collection file").withArgName("path").hasArg()
            .isRequired().create(INPUT_PATH_OPTION));
    options.addOption(OptionBuilder.withDescription("two-letter collection language code")
            .withArgName("en|de|fr|zh|es|ar|tr").hasArg().isRequired().create(LANGUAGE_OPTION));
    options.addOption(OptionBuilder.withDescription("path to stopwords file").withArgName("path").hasArg()
            .create(STOPWORDS_OPTION));/*from   w  w w . j a v  a  2  s  .c o m*/
    options.addOption(OptionBuilder.withDescription("collection name").withArgName("path").hasArg()
            .create(COLLECTION_NAME_OPTION));
    try {

        FileSystem fs = FileSystem.get(conf);

        CommandLine cmdline;
        CommandLineParser parser = new GnuParser();
        cmdline = parser.parse(options, args);

        String collection = cmdline.getOptionValue(INPUT_PATH_OPTION);
        String indexRootPath = cmdline.getOptionValue(INDEX_PATH_OPTION);
        String language = cmdline.getOptionValue(LANGUAGE_OPTION);
        String tokenizerClass = cmdline.getOptionValue(TOKENIZER_CLASS_OPTION);
        String stopwordsFile = null;
        String tokenizerPath = null;

        conf.set(Constants.CollectionPath, collection);
        conf.set(Constants.IndexPath, indexRootPath);
        conf.set(Constants.Tokenizer, tokenizerClass);
        conf.set(Constants.Language, language);

        if (cmdline.hasOption(COLLECTION_NAME_OPTION)) {
            conf.set(Constants.CollectionName, cmdline.getOptionValue(COLLECTION_NAME_OPTION));
        }
        if (cmdline.hasOption(STOPWORDS_OPTION)) {
            stopwordsFile = cmdline.getOptionValue(STOPWORDS_OPTION);
            conf.set(Constants.StopwordList, stopwordsFile);
        }
        if (cmdline.hasOption(TOKENIZER_MODEL_OPTION)) {
            tokenizerPath = cmdline.getOptionValue(TOKENIZER_MODEL_OPTION);
            conf.set(Constants.TokenizerData, tokenizerPath);
        }

        LOG.info("Tool name: " + PreprocessTrecForeign.class.getCanonicalName());
        LOG.info(" - Collection path: " + collection);
        LOG.info(" - Index path: " + indexRootPath);
        LOG.info(" - Language: " + language);
        LOG.info(" - Stop-word removal?: " + stopwordsFile);
        LOG.info(" - Tokenizer class: " + tokenizerClass);
        LOG.info(" - Tokenizer path: " + tokenizerPath);

        // Create the index directory if it doesn't already exist.
        Path p = new Path(indexRootPath);
        if (!fs.exists(p)) {
            LOG.info("index directory doesn't exist, creating...");
            fs.mkdirs(p);
        }
    } catch (IOException exp) {
        LOG.info("Error creating index directory: " + exp.getMessage());
        exp.printStackTrace();
    } catch (ParseException exp) {
        LOG.info("Error parsing command line: " + exp.getMessage());
        throw new RuntimeException();
    }

    return conf;
}

From source file:com.mellanox.r4h.MiniDFSClusterManager.java

/**
 * Creates configuration options object.
 *///from  w  w  w .  j a  va  2s  . c o  m
@SuppressWarnings("static-access")
private Options makeOptions() {
    Options options = new Options();
    options.addOption("datanodes", true, "How many datanodes to start (default 1)")
            .addOption("format", false, "Format the DFS (default false)")
            .addOption("cmdport", true, "Which port to listen on for commands (default 0--we choose)")
            .addOption("nnport", true, "NameNode port (default 0--we choose)")
            .addOption("namenode", true,
                    "URL of the namenode (default " + "is either the DFS cluster or a temporary dir)")
            .addOption(OptionBuilder.hasArgs().withArgName("property=value")
                    .withDescription("Options to pass into configuration object").create("D"))
            .addOption(OptionBuilder.hasArg().withArgName("path")
                    .withDescription("Save configuration to this XML file.").create("writeConfig"))
            .addOption(OptionBuilder.hasArg().withArgName("path")
                    .withDescription("Write basic information to this JSON file.").create("writeDetails"))
            .addOption(OptionBuilder.withDescription("Prints option help.").create("help"));
    return options;
}

From source file:de.unidue.inf.is.ezdl.gframedl.EzDL.java

private static void parseCommandLine(String[] args) {
    CommandLine cmd = null;/*  w ww  .  j a  v a  2  s . co m*/
    Options parserOptions = new Options();
    parserOptions.addOption(OPTION_DEBUG, false, "marks this session as a debug session");
    OptionBuilder.withArgName(OPTION_DIR);
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("the directory with the config files");
    parserOptions.addOption(OptionBuilder.create(OPTION_DIR));

    try {
        cmd = parser.parse(parserOptions, args);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        System.out.println("EzDL " + EzDLConstants.CLIENT_VERSION);
        formatter.printHelp("ezdl", parserOptions);
        System.exit(1);
    }

    if (cmd.hasOption(OPTION_DEBUG)) {
        System.out.println("debug option found");
        sessionType = SessionType.DEBUG;
    } else {
        sessionType = DEFAULT_SESSION_TYPE;
    }

    if (cmd.hasOption(OPTION_DIR)) {
        String dir = cmd.getOptionValue(OPTION_DIR);
        Config.setPropertyDir(dir);
        PropertiesUtils.setPropertyDir(dir);
        Config.getInstance().refreshProperties();
    }
}

From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java

/**
 * Creates and adds a minimum state size option to a given {@link Options}
 * object./*  ww  w  .  j a  v  a  2  s . c  om*/
 * 
 * @param options
 *            The <code>Options</code> object to add to.
 */
private static void addMinStateSizeOption(final Options options) {
    OptionBuilder.withLongOpt(MIN_STATE_SIZE_KEY_LONG);
    OptionBuilder.withDescription(MIN_STATE_SIZE_DESCR);
    OptionBuilder.hasArg();
    OptionBuilder.withArgName(SIZE_ARG_NAME);
    OptionBuilder.withType(int.class);

    final Option minStateSize = OptionBuilder.create(MIN_STATE_SIZE_KEY);
    options.addOption(minStateSize);
}

From source file:com.cloudera.sqoop.tool.MergeTool.java

/**
 * Construct the set of options that control imports, either of one
 * table or a batch of tables.// ww  w.  ja v a 2 s.  c o  m
 * @return the RelatedOptions that can be used to parse the import
 * arguments.
 */
protected RelatedOptions getMergeOptions() {
    // Imports
    RelatedOptions mergeOpts = new RelatedOptions("Merge arguments");

    mergeOpts.addOption(OptionBuilder.withArgName("file").hasArg()
            .withDescription("Load class from specified jar file").withLongOpt(JAR_FILE_NAME_ARG).create());

    mergeOpts.addOption(OptionBuilder.withArgName("name").hasArg()
            .withDescription("Specify record class name to load").withLongOpt(CLASS_NAME_ARG).create());

    mergeOpts.addOption(OptionBuilder.withArgName("path").hasArg()
            .withDescription("Path to the more recent data set").withLongOpt(NEW_DATASET_ARG).create());

    mergeOpts.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("Path to the older data set")
            .withLongOpt(OLD_DATASET_ARG).create());

    mergeOpts.addOption(OptionBuilder.withArgName("path").hasArg()
            .withDescription("Destination path for merged results").withLongOpt(TARGET_DIR_ARG).create());

    mergeOpts.addOption(OptionBuilder.withArgName("column").hasArg()
            .withDescription("Key column to use to join results").withLongOpt(MERGE_KEY_ARG).create());

    // Since the "common" options aren't used in the merge tool,
    // add these settings here.
    mergeOpts.addOption(OptionBuilder.withDescription("Print more information while working")
            .withLongOpt(VERBOSE_ARG).create());
    mergeOpts.addOption(
            OptionBuilder.withDescription("Print usage instructions").withLongOpt(HELP_ARG).create());

    return mergeOpts;
}

From source file:mitm.application.djigzo.tools.Upgrade.java

@SuppressWarnings("static-access")
private Options createCommandLineOptions() {
    Options options = new Options();

    Option helpOption = OptionBuilder.withDescription("Show help").create("help");
    helpOption.setRequired(false);//from   w w  w  .j av a  2 s. c om
    options.addOption(helpOption);

    Option versionOption = OptionBuilder.withArgName("version").hasArg().withDescription("version")
            .create("version");
    versionOption.setRequired(true);
    options.addOption(versionOption);

    Option userOption = OptionBuilder.withArgName("user").hasArg().withDescription("user").create("user");
    userOption.setRequired(false);
    options.addOption(userOption);

    Option passwordOption = OptionBuilder.withArgName("password").hasArg().withDescription("password")
            .create("password");
    passwordOption.setRequired(false);
    options.addOption(passwordOption);

    hostOption = OptionBuilder.withArgName("host").hasArg()
            .withDescription("The host to connect to (def: 127.0.0.1)").create("host");
    options.addOption(hostOption);

    portOption = OptionBuilder.withArgName("port").hasArg()
            .withDescription("The port to use (def: " + DjigzoWSDefaults.PORT + ")").create("port");
    options.addOption(portOption);

    return options;
}

From source file:net.sf.clichart.main.OptionParser.java

private void addOption(org.apache.commons.cli.Options optionDefs, String[] optionDetails, boolean hasArgument) {
    // OptionBuilder is a stateful class
    OptionBuilder.withLongOpt(optionDetails[1]);
    OptionBuilder.withDescription(optionDetails[2]);

    if (hasArgument) {
        OptionBuilder.hasArg(true);//from w  ww.ja va 2  s . c o m
        OptionBuilder.withValueSeparator();
    }

    if (optionDetails[0] != null) {
        optionDefs.addOption(OptionBuilder.create(optionDetails[0]));
    } else {
        optionDefs.addOption(OptionBuilder.create());
    }
}

From source file:com.archivas.clienttools.arcmover.cli.ArcDelete.java

@SuppressWarnings({ "static-access", "AccessStaticViaInstance" })
public Options getOptions() {
    if (cliOptions == null) {
        Options options = new Options();

        // *** Adding a new option needs to be added to the cliOrder list
        // Note, you cannot do required options with this library and help so we have to add all
        // as non-required
        // and deal with it when parsing
        options.addOption(OptionBuilder.withDescription("Displays this help text (the default behavior).")
                .withLongOpt(HELP_OPTION).create("h"));

        // Required
        options.addOption(OptionBuilder.withArgName("profile_name").hasArg().withDescription(
                "Target location for the delete operation: either a namespace profile name or LFS for the local file system.")
                .withLongOpt(PROFILE_OPTION).create("p"));
        options.addOption(OptionBuilder.withArgName("path").hasArg()
                .withDescription("Directory in which to perform the delete operation.").withLongOpt(PATH_OPTION)
                .create());//  w  w w.jav a2  s  .com
        options.addOption(OptionBuilder.withArgName("operation_type").hasArg().withDescription(
                "Type of operation to perform: delete, purge, privileged-delete, or privileged-purge.  If omitted, defaults to delete.  Only supported for HCP namespaces.")
                .withLongOpt(OPERATION_OPTION).create());
        options.addOption(OptionBuilder.withArgName("string").hasArg().withDescription(
                "Specifies the reason for a privileged operation.  The string must be from one through 1024 characters long.  Required and only supported for a privileged operation.")
                .withLongOpt(REASON_OPTION).create()); // Required

        options.addOption(OptionBuilder.withArgName("job_name").hasOptionalArg().withDescription(
                "Reruns the delete job with the given job name if provide, if no name is provided it reruns the last delete job run.  When rerunning you can change the load and export settings.  Any changes to the profile, path, or operation-type will not change what is set in the job.")
                .withLongOpt(RERUN).create());
        options.addOption(OptionBuilder.withArgName("job_name").hasOptionalArg().withDescription(
                "Resumes the delete job from where it left off, if no name is provided it resumes the last delete job run.  When rerunning you can change the load and export settings.  Any changes to the profile, path, or operation-type will not change what is set in the job.")
                .withLongOpt(RESUME).create());

        // Optional
        options.addOption(getInsecureSSLOption());

        // results_types is only not shared because CONFLICT is not a valid option for delete
        // jobs
        options.addOption(OptionBuilder.withArgName("results_types").hasArg().withDescription(
                "Types of results lists to export: either ALL or a comma-separated list that includes one or more of SUCCESS, FAILURE, and JOBLIST.  If omitted no results lists are exported.")
                .withLongOpt(EXPORT_RESULTS_TYPE).create());

        getSharedOptions(options);
        cliOptions = options;
    }
    return cliOptions;
}

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

/**
  * Build command line options object./*from w w w. j a  v a2s  . 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);

    return opts;
}