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

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

Introduction

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

Prototype

public static OptionBuilder withArgName(String name) 

Source Link

Document

The next Option created will have the specified argument value name.

Usage

From source file:SearchApiExample.java

/**
  * Build command line options object.//from   w  w w .  ja v a2  s  . com
  */
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);

    OptionBuilder.withArgName("keywords");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("keywords");
    opts.addOption(OptionBuilder.create(KEYWORDS_OPTION));

    OptionBuilder.withArgName("name");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("name");
    opts.addOption(OptionBuilder.create(NAME_OPTION));

    OptionBuilder.withArgName("company");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("company");
    opts.addOption(OptionBuilder.create(COMPANY_OPTION));

    OptionBuilder.withArgName("current-company");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("current-company");
    opts.addOption(OptionBuilder.create(CURRENT_COMPANY_OPTION));

    OptionBuilder.withArgName("title");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("title");
    opts.addOption(OptionBuilder.create(TITLE_OPTION));

    OptionBuilder.withArgName("current-title");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("current-title");
    opts.addOption(OptionBuilder.create(CURRENT_TITLE_OPTION));

    OptionBuilder.withArgName("industry-code");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("industry-code");
    opts.addOption(OptionBuilder.create(INDUSTRY_CODE_OPTION));

    OptionBuilder.withArgName("search-location-type");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("search-location-type");
    opts.addOption(OptionBuilder.create(SEARCH_LOCATION_TYPE_OPTION));

    OptionBuilder.withArgName("country-code");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("country-code");
    opts.addOption(OptionBuilder.create(COUNTRY_CODE_OPTION));

    OptionBuilder.withArgName("postal-code");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("postal-code");
    opts.addOption(OptionBuilder.create(POSTAL_CODE_OPTION));

    OptionBuilder.withArgName("network");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("network");
    opts.addOption(OptionBuilder.create(NETWORK_OPTION));

    return opts;
}

From source file:edu.umd.shrawanraina.BuildPersonalizedPageRankRecords.java

/**
 * Runs this tool.//w  ww.ja  va  2 s .  co m
 */
@SuppressWarnings({ "static-access" })
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES));
    options.addOption(
            OptionBuilder.withArgName("node").hasArg().withDescription("source nodes").create(SOURCES));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT) || !cmdline.hasOption(NUM_NODES)
            || !cmdline.hasOption(SOURCES)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inputPath = cmdline.getOptionValue(INPUT);
    String outputPath = cmdline.getOptionValue(OUTPUT);
    int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES));
    String sources = cmdline.getOptionValue(SOURCES);

    LOG.info("Tool name: " + BuildPersonalizedPageRankRecords.class.getSimpleName());
    LOG.info(" - inputDir: " + inputPath);
    LOG.info(" - outputDir: " + outputPath);
    LOG.info(" - numNodes: " + n);
    LOG.info(" - sources: " + sources);

    Configuration conf = getConf();
    conf.setInt(NODE_CNT_FIELD, n);
    conf.setStrings("sources", sources);
    conf.setInt("mapred.min.split.size", 1024 * 1024 * 1024);

    Job job = Job.getInstance(conf);
    job.setJobName(BuildPersonalizedPageRankRecords.class.getSimpleName() + ":" + inputPath);
    job.setJarByClass(BuildPersonalizedPageRankRecords.class);

    job.setNumReduceTasks(0);

    FileInputFormat.addInputPath(job, new Path(inputPath));
    FileOutputFormat.setOutputPath(job, new Path(outputPath));

    job.setInputFormatClass(TextInputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapOutputKeyClass(IntWritable.class);
    job.setMapOutputValueClass(PageRankNodeUpd.class);

    job.setOutputKeyClass(IntWritable.class);
    job.setOutputValueClass(PageRankNodeUpd.class);

    job.setMapperClass(MyMapper.class);

    // Delete the output directory if it exists already.
    FileSystem.get(conf).delete(new Path(outputPath), true);

    job.waitForCompletion(true);

    return 0;
}

From source file:io.bfscan.clueweb09.BuildPForDocVectors.java

/**
 * Runs this tool./*w w w  .  j a va2  s  . c  o  m*/
 */
@SuppressWarnings("static-access")
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("dictionary").create(DICTIONARY_OPTION));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of reducers")
            .create(REDUCERS_OPTION));
    options.addOption(OptionBuilder.withArgName("string " + AnalyzerFactory.getOptions()).hasArg()
            .withDescription("preprocessing").create(PREPROCESSING));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT_OPTION) || !cmdline.hasOption(OUTPUT_OPTION)
            || !cmdline.hasOption(DICTIONARY_OPTION) || !cmdline.hasOption(PREPROCESSING)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String input = cmdline.getOptionValue(INPUT_OPTION);
    String output = cmdline.getOptionValue(OUTPUT_OPTION);
    String dictionary = cmdline.getOptionValue(DICTIONARY_OPTION);
    String preprocessing = cmdline.getOptionValue(PREPROCESSING);

    Job job = new Job(getConf(), BuildPForDocVectors.class.getSimpleName() + ":" + input);
    job.setJarByClass(BuildPForDocVectors.class);

    LOG.info("Tool name: " + BuildPForDocVectors.class.getSimpleName());
    LOG.info(" - input: " + input);
    LOG.info(" - output: " + output);
    LOG.info(" - dictionary: " + dictionary);
    LOG.info(" - preprocessing: " + preprocessing);

    if (cmdline.hasOption(REDUCERS_OPTION)) {
        int numReducers = Integer.parseInt(cmdline.getOptionValue(REDUCERS_OPTION));
        LOG.info(" - reducers: " + numReducers);
        job.setNumReduceTasks(numReducers);
    } else {
        job.setNumReduceTasks(0);
    }

    FileInputFormat.setInputPaths(job, input);
    FileOutputFormat.setOutputPath(job, new Path(output));

    job.getConfiguration().set(DICTIONARY_OPTION, dictionary);
    job.getConfiguration().set(PREPROCESSING, preprocessing);

    job.setInputFormatClass(ClueWeb09InputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(IntArrayWritable.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntArrayWritable.class);

    job.setMapperClass(MyMapper.class);

    FileSystem.get(getConf()).delete(new Path(output), true);

    long startTime = System.currentTimeMillis();
    job.waitForCompletion(true);
    LOG.info("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds");

    return 0;
}

From source file:com.google.api.ads.adwords.awreporting.server.AwReportingServer.java

/**
 * Creates the command line options.//  w w w  . jav a 2s  .c  o m
 *
 * @return the {@link Options}.
 */
private static Options createCommandLineOptions() {

    Options options = new Options();
    Option help = new Option("help", "print this message");
    options.addOption(help);

    OptionBuilder.withArgName("startServer");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription("Starts the Rest Server. No dates required");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("startServer"));

    OptionBuilder.withArgName("processKratus");
    OptionBuilder.hasArg(false);
    OptionBuilder
            .withDescription("Process Kratus processes the 7 reports peraccount and creates a daily Kratu");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("processKratus"));

    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("aw-reporting-server-sample.properties file "
            + " (./aw-reporting-server-sample.properties by default if not provided)");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("file"));

    OptionBuilder.withArgName("YYYYMMDD");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("Start date for CUSTOM_DATE Reports (YYYYMMDD)");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("startDate"));

    OptionBuilder.withArgName("YYYMMDD");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("End date for CUSTOM_DATE Reports (YYYYMMDD)");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("endDate"));

    OptionBuilder.withArgName("DateRangeType");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("ReportDefinitionDateRangeType");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("dateRange"));

    OptionBuilder.withArgName("accountIdsFile");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("Consider ONLY the account IDs specified on the file to run the report");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("accountIdsFile"));

    OptionBuilder.withArgName("verbose");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription("The application will print all the tracing on the console");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("verbose"));

    OptionBuilder.withArgName("debug");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription(
            "Will display all the debug information. " + "If the option 'verbose' is activated, "
                    + "all the information will be displayed on the console as well");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("debug"));

    return options;
}

From source file:io.bfscan.clueweb12.BuildVByteDocVectors.java

/**
 * Runs this tool.//from  w  ww  .ja  va 2 s . com
 */
@SuppressWarnings("static-access")
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("dictionary").create(DICTIONARY_OPTION));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of reducers")
            .create(REDUCERS_OPTION));
    options.addOption(OptionBuilder.withArgName("string " + AnalyzerFactory.getOptions()).hasArg()
            .withDescription("preprocessing").create(PREPROCESSING));

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT_OPTION) || !cmdline.hasOption(OUTPUT_OPTION)
            || !cmdline.hasOption(DICTIONARY_OPTION) || !cmdline.hasOption(PREPROCESSING)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String input = cmdline.getOptionValue(INPUT_OPTION);
    String output = cmdline.getOptionValue(OUTPUT_OPTION);
    String dictionary = cmdline.getOptionValue(DICTIONARY_OPTION);
    String preprocessing = cmdline.getOptionValue(PREPROCESSING);

    Job job = Job.getInstance(getConf());
    job.setJobName(BuildVByteDocVectors.class.getSimpleName() + ":" + input);
    job.setJarByClass(BuildVByteDocVectors.class);

    LOG.info("Tool name: " + BuildVByteDocVectors.class.getSimpleName());
    LOG.info(" - input: " + input);
    LOG.info(" - output: " + output);
    LOG.info(" - dictionary: " + dictionary);
    LOG.info(" - preprocessing: " + preprocessing);

    if (cmdline.hasOption(REDUCERS_OPTION)) {
        int numReducers = Integer.parseInt(cmdline.getOptionValue(REDUCERS_OPTION));
        LOG.info(" - reducers: " + numReducers);
        job.setNumReduceTasks(numReducers);
    } else {
        job.setNumReduceTasks(0);
    }

    FileInputFormat.setInputPaths(job, input);
    FileOutputFormat.setOutputPath(job, new Path(output));

    job.getConfiguration().set(DICTIONARY_OPTION, dictionary);
    job.getConfiguration().set(PREPROCESSING, preprocessing);

    job.setInputFormatClass(ClueWeb12InputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(BytesWritable.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(BytesWritable.class);

    job.setMapperClass(MyMapper.class);

    FileSystem.get(getConf()).delete(new Path(output), true);

    long startTime = System.currentTimeMillis();
    job.waitForCompletion(true);
    LOG.info("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds");

    return 0;
}

From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.KratuMain.java

/**
 * Creates the command line options.//ww w .java2  s .com
 *
 * @return the {@link Options}.
 */
private static Options createCommandLineOptions() {

    Options options = new Options();
    Option help = new Option("help", "print this message");
    options.addOption(help);

    OptionBuilder.withArgName("startServer");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription("Starts the Rest Server. No dates required");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("startServer"));

    OptionBuilder.withArgName("processKratus");
    OptionBuilder.hasArg(false);
    OptionBuilder
            .withDescription("Process Kratus processes the 7 reports peraccount and creates a daily Kratu");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("processKratus"));

    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("kratubackend-sample.properties file "
            + " (./kratubackend-sample.properties by default if not provided)");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("file"));

    OptionBuilder.withArgName("YYYYMMDD");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("Start date for CUSTOM_DATE Reports (YYYYMMDD)");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("startDate"));

    OptionBuilder.withArgName("YYYMMDD");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("End date for CUSTOM_DATE Reports (YYYYMMDD)");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("endDate"));

    OptionBuilder.withArgName("DateRangeType");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("ReportDefinitionDateRangeType");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("dateRange"));

    OptionBuilder.withArgName("accountIdsFile");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("Consider ONLY the account IDs specified on the file to run the report");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("accountIdsFile"));

    OptionBuilder.withArgName("verbose");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription("The application will print all the tracing on the console");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("verbose"));

    OptionBuilder.withArgName("debug");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription(
            "Will display all the debug information. " + "If the option 'verbose' is activated, "
                    + "all the information will be displayed on the console as well");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("debug"));

    return options;
}

From source file:fr.ens.biologie.genomique.eoulsan.actions.IntegrationTestAction.java

/**
 * Create options for command line//from   ww w.  j  a v a 2 s  . c  o m
 * @return an Options object
 */
@SuppressWarnings("static-access")
private Options makeOptions() {

    // create Options object
    final Options options = new Options();

    // Help option
    options.addOption("h", "help", false, "display this help");

    // Path to test configuration
    options.addOption(OptionBuilder.withArgName("file").hasArg(true).withDescription("configuration file")
            .create("testconf"));

    // Path to application version to execute
    options.addOption(OptionBuilder.withArgName("appliPath").hasArg()
            .withDescription("application path to launch").create("exec"));

    // Optional, path to file with list name tests to treat
    options.addOption(OptionBuilder.withArgName("file").hasArg(true)
            .withDescription("optional: files with tests name to launch").withLongOpt("file").create('f'));

    // Optional, the name of the test to execute
    options.addOption(OptionBuilder.withArgName("test").hasArg(true)
            .withDescription("optional: test name to launch").withLongOpt("test").create('t'));

    // Optional, force generated expected data
    options.addOption(OptionBuilder.withArgName("mode").hasArg().withDescription(
            "optional: mode for generate data expected: all (remove existing) or mode to generate no exists directory new")
            .create("expected"));

    // Optional, the test output directory
    options.addOption(OptionBuilder.withArgName("outputdir").hasArg(true)
            .withDescription("optional: test output directory").withLongOpt("dir").create('d'));

    // Optional, path to TestNG report directory
    options.addOption(OptionBuilder.withArgName("file").hasArg(true).withDescription("TestNG report directory")
            .create('o'));

    return options;
}

From source file:com.archivas.clienttools.arcmover.cli.ArcCopy.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("source_profile").hasArg().withDescription(
                "Source for the copy operation: either a namespace profile name or LFS for the local file system.")
                .withLongOpt(SOURCE_PROFILE_OPTION).create("s"));
        options.addOption(OptionBuilder.withArgName("destination_profile").hasArg().withDescription(
                "Destination for the copy operation: either a namespace profile name or LFS for the local file system.")
                .withLongOpt(DESTINATION_PROFILE_OPTION).create("d"));
        options.addOption(OptionBuilder.withArgName("destination_path").hasArg()
                .withDescription("Destination directory path.").withLongOpt(DESTINATION_PATH_OPTION).create());

        // Optional
        options.addOption(OptionBuilder.withArgName("source_path").hasArg()
                .withDescription("Source directory path.").withLongOpt(SOURCE_PATH_OPTION).create());
        options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription(
                "Custom metadata path.  Can be relative or absolute.  This option applies only when copying from the local file system to a namespace.")
                .withLongOpt(CUSTOM_METADATA_OPTION).create());

        options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription(
                "ACL path.  Can be relative or absolute.  This option applies only when copying from the local file system to a HCP 5.0 or later namespace.")
                .withLongOpt(ACL_OPTION).create());

        options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription(
                "Owner's name.  This option applies only when copying from the local file system to a HCP 5.0 or later namespace.")
                .withLongOpt(OWNER_OPTION).create());

        options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription(
                "Owner's domain.  This option applies only when copying from the local file system to a HCP 5.0 or later namespace.")
                .withLongOpt(DOMAIN_OPTION).create());

        options.addOption(OptionBuilder.withArgName("true|false").hasArg().withDescription(
                "Specifies whether copied objects should be marked for indexing.  This option applies only when copying from the local file system to a namespace.")
                .withLongOpt(INDEX_OPTION).create());
        options.addOption(OptionBuilder.withArgName("true|false").hasArg().withDescription(
                "Specifies whether copied objects should be marked for shredding.  This option applies only when copying from the local file system to a namespace.")
                .withLongOpt(SHRED_OPTION).create());
        options.addOption(OptionBuilder.withArgName("true|false").hasArg().withDescription(
                "Specifies whether copied objects should be placed on hold.  This option applies only when copying from the local file system to a namespace.")
                .withLongOpt(HOLD_OPTION).create());
        options.addOption(OptionBuilder.withArgName("retention_setting").hasArg().withDescription(
                "Retention setting for copied objects.  This option applies only when copying from the local file system to a namespace.")
                .withLongOpt(RETENTION_OPTION).create());
        options.addOption(OptionBuilder.withArgName("integer").hasArg().withDescription(
                "Group ID to use for the owner of copied objects.  This option applies only when copying from the local file system to a namespace.")
                .withLongOpt(GID_OPTION).create());
        options.addOption(OptionBuilder.withArgName("integer").hasArg().withDescription(
                "User ID to use for the owner of copied objects.  This option applies only when copying from the local file system to a namespace.")
                .withLongOpt(UID_OPTION).create());
        options.addOption(OptionBuilder.withArgName("octal_value").hasArg().withDescription(
                "POSIX permissions for copied objects; for example, 664.  This option applies only when copying from the local file system to a namespace.")
                .withLongOpt(FILE_PERMS_OPTION).create());
        options.addOption(OptionBuilder.withArgName("octal_value").hasArg().withDescription(
                "POSIX permissions for new destination directories; for example, 664.  This option applies only when copying from the local file system to a namespace.")
                .withLongOpt(DIR_PERMS_OPTION).create());

        options.addOption(OptionBuilder.withArgName("job_name").hasOptionalArg().withDescription(
                "Reruns the copy job with the given job name if provide, if no name is provided it reruns the last copy job run.  When rerunning you can change the load and export settings.  Any changes to profiles, paths or metadata values will not change what is set in the job.")
                .withLongOpt(RERUN).create());
        options.addOption(OptionBuilder.withArgName("job_name").hasOptionalArg().withDescription(
                "Resumes the copy job from where it left off, if no name is provided it resumes the last copy job run.  When rerunning you can change the load and export settings.  Any changes to profiles, paths or metadata values will not change what is set in the job.")
                .withLongOpt(RESUME).create());
        options.addOption(OptionBuilder.withDescription("Treat conflict (409) failures as successes.")
                .withLongOpt(IGNORE_CONFLICTS).create());
        // results_types is only not shared because CONFLICT is not a valid option for delete
        // jobs//from www.j a v a 2  s  .  c om
        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, JOBLIST and CONFLICT.  If omitted no results lists are exported.")
                .withLongOpt(EXPORT_RESULTS_TYPE).create());
        getSharedOptions(options);

        cliOptions = options;
    }
    return cliOptions;
}

From source file:WikipediaDocnoMappingBuilder.java

@SuppressWarnings("static-access")
@Override//from w w  w  . j  a  va 2 s  .  com
public int run(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(
            OptionBuilder.withArgName("path").hasArg().withDescription("XML dump file").create(INPUT_OPTION));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output file")
            .create(OUTPUT_FILE_OPTION));
    options.addOption(OptionBuilder.withArgName("en|sv|de|cs|es|zh|ar|tr").hasArg()
            .withDescription("two-letter language code").create(LANGUAGE_OPTION));
    options.addOption(KEEP_ALL_OPTION, false, "keep all pages");

    CommandLine cmdline;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        return -1;
    }

    if (!cmdline.hasOption(INPUT_OPTION) || !cmdline.hasOption(OUTPUT_FILE_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String language = null;
    if (cmdline.hasOption(LANGUAGE_OPTION)) {
        language = cmdline.getOptionValue(LANGUAGE_OPTION);
        if (language.length() != 2) {
            System.err.println("Error: \"" + language + "\" unknown language!");
            return -1;
        }
    }

    String inputPath = cmdline.getOptionValue(INPUT_OPTION);
    String outputFile = cmdline.getOptionValue(OUTPUT_FILE_OPTION);
    boolean keepAll = cmdline.hasOption(KEEP_ALL_OPTION);

    String tmpPath = "tmp-" + WikipediaDocnoMappingBuilder.class.getSimpleName() + "-" + RANDOM.nextInt(10000);

    LOG.info("Tool name: " + this.getClass().getName());
    LOG.info(" - input: " + inputPath);
    LOG.info(" - output file: " + outputFile);
    LOG.info(" - keep all pages: " + keepAll);
    LOG.info(" - language: " + language);

    // Job job = Job.getInstance(getConf());
    JobConf conf = new JobConf(WikipediaDocnoMappingBuilder.class);
    conf.setJarByClass(WikipediaDocnoMappingBuilder.class);
    conf.setJobName(String.format("BuildWikipediaDocnoMapping[%s: %s, %s: %s, %s: %s]", INPUT_OPTION, inputPath,
            OUTPUT_FILE_OPTION, outputFile, LANGUAGE_OPTION, language));

    conf.setBoolean(KEEP_ALL_OPTION, keepAll);
    // .getConfiguration().setBoolean(KEEP_ALL_OPTION, keepAll);
    if (language != null) {
        conf.set("wiki.language", language);
    }
    conf.setNumReduceTasks(1);

    FileInputFormat.addInputPath(conf, new Path(inputPath));
    FileOutputFormat.setOutputPath(conf, new Path(tmpPath));
    FileOutputFormat.setCompressOutput(conf, false);

    conf.setOutputKeyClass(IntWritable.class);
    conf.setOutputValueClass(IntWritable.class);
    conf.setInputFormat(WikipediaPageInputFormat.class);
    conf.setOutputFormat(TextOutputFormat.class);

    conf.setMapperClass(MyMapper.class);
    conf.setReducerClass(MyReducer.class);

    // Delete the output directory if it exists already.
    FileSystem.get(getConf()).delete(new Path(tmpPath), true);

    // job.waitForCompletion(true);

    RunningJob job = JobClient.runJob(conf);
    job.waitForCompletion();

    // JobClient jobClient = new JobClient(conf);
    long cnt = keepAll ? job.getCounters().findCounter(PageTypes.TOTAL).getValue()
            : job.getCounters().findCounter(PageTypes.ARTICLE).getValue();

    WikipediaDocnoMapping.writeDocnoMappingData(FileSystem.get(getConf()), tmpPath + "/part-00000", (int) cnt,
            outputFile);

    FileSystem.get(getConf()).delete(new Path(tmpPath), true);

    return 0;
}