Example usage for org.apache.commons.cli GnuParser GnuParser

List of usage examples for org.apache.commons.cli GnuParser GnuParser

Introduction

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

Prototype

GnuParser

Source Link

Usage

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

@Override
public void action(final List<String> arguments) {

    System.err.println(//  w w w.j  a va2  s  .  c om
            "WARNING: the action \"" + getName() + "\" is currently under development for the next version of "
                    + Globals.APP_NAME + " and may actually not work.");

    final Options options = makeOptions();
    final CommandLineParser parser = new GnuParser();

    String jobDescription = null;

    int argsOptions = 0;

    try {

        // parse the command line arguments
        final CommandLine line = parser.parse(options, arguments.toArray(new String[arguments.size()]), true);

        // Help option
        if (line.hasOption("help")) {
            help(options);
        }

        if (line.hasOption("d")) {

            jobDescription = line.getOptionValue("d");
            argsOptions += 2;
        }

    } catch (ParseException e) {
        Common.errorExit(e, "Error while parsing command line arguments: " + e.getMessage());
    }

    if (arguments.size() != argsOptions + 3) {
        help(options);
    }

    final File paramFile = new File(arguments.get(argsOptions));
    final File designFile = new File(arguments.get(argsOptions + 1));
    final DataFile s3Path = new DataFile(
            StringUtils.replacePrefix(arguments.get(argsOptions + 2), "s3:/", "s3n:/"));

    // Execute program in AWS mode
    run(paramFile, designFile, s3Path, jobDescription);
}

From source file:edu.umd.gorden2.PartitionGraph.java

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

    options.addOption(new Option(RANGE, "use range partitioner"));

    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("num").hasArg().withDescription("number of partitions")
            .create(NUM_PARTITIONS));

    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(NUM_PARTITIONS)) {
        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 inPath = cmdline.getOptionValue(INPUT);
    String outPath = cmdline.getOptionValue(OUTPUT);
    int nodeCount = Integer.parseInt(cmdline.getOptionValue(NUM_NODES));
    int numParts = Integer.parseInt(cmdline.getOptionValue(NUM_PARTITIONS));
    boolean useRange = cmdline.hasOption(RANGE);

    LOG.info("Tool name: " + PartitionGraph.class.getSimpleName());
    LOG.info(" - input dir: " + inPath);
    LOG.info(" - output dir: " + outPath);
    LOG.info(" - num partitions: " + numParts);
    LOG.info(" - node cnt: " + nodeCount);
    LOG.info(" - use range partitioner: " + useRange);

    Configuration conf = getConf();
    conf.setInt("NodeCount", nodeCount);

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

    job.setNumReduceTasks(numParts);

    FileInputFormat.setInputPaths(job, new Path(inPath));
    FileOutputFormat.setOutputPath(job, new Path(outPath));

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

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

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

    //if (useRange) {
    //job.setPartitionerClass(RangePartitioner.class);
    //}

    FileSystem.get(conf).delete(new Path(outPath), true);

    job.waitForCompletion(true);

    return 0;
}

From source file:com.googlecode.icegem.cacheutils.regioncomparator.CompareTool.java

protected void parseCommandLineArguments(String[] commandLineArguments) {
    Options options = constructGnuOptions();
    if (commandLineArguments.length < 1) {
        printHelp(options);/*from w w w.  j a  v a 2s  . c  o m*/
        Utils.exitWithSuccess();
    }
    CommandLineParser parser = new GnuParser();
    try {
        CommandLine line = parser.parse(options, commandLineArguments);
        if (!line.hasOption("region") || line.hasOption("help")
                || !(line.hasOption("locators") || line.hasOption("servers"))) {
            printHelp(options);
            Utils.exitWithSuccess();
        }
        if (line.hasOption("packages"))
            scanPackagesOption = Arrays.asList(line.getOptionValue("packages").split(","));
        regionName = line.getOptionValue("region");
        if (line.hasOption("locators"))
            locatorsProperties = line.getOptionProperties("locators");
        if (line.hasOption("servers"))
            serversOption = line.getOptionValue("servers");

    } catch (ParseException exp) {
        System.err.println("Parsing options failed. " + exp.getMessage());
        printHelp(options);
        Utils.exitWithSuccess();
    }
}

From source file:com.zimbra.cs.account.ldap.upgrade.LdapUpgrade.java

public static void upgrade(String[] args) throws ServiceException {
    printer.println("\n\n--------------");
    printer.print(LdapUpgrade.class.getCanonicalName() + " ");
    for (String arg : args) {
        printer.print(arg + " ");
    }/*  w  ww .  j a  v a  2  s  . co  m*/
    printer.println();
    printer.println("--------------");

    CliUtil.toolSetup();

    CommandLine cl = null;
    try {
        CommandLineParser parser = new GnuParser();
        Options options = getAllOptions();
        cl = parser.parse(options, args);
        if (cl == null) {
            throw new ParseException("");
        }
    } catch (ParseException e) {
        usage(e, null, null);
        System.exit(1);
    }

    if (cl.hasOption(O_HELP)) {
        usage();
        System.exit(0);
    }

    if (cl.hasOption(O_DESCRIBE)) {
        String bug = cl.getOptionValue(O_DESCRIBE);
        UpgradeOp upgradeOp = getUpgradeOp(bug, printer);
        upgradeOp.describe();
        System.exit(0);
    }

    if (cl.hasOption(O_DESCRIBE_ALL)) {
        for (UpgradeTask task : UpgradeTask.values()) {
            String bug = task.getBug();
            UpgradeOp upgradeOp = getUpgradeOp(bug, printer);
            upgradeOp.describe();
        }
        System.exit(0);
    }

    if (!cl.hasOption(O_BUG)) {
        usage();
        System.exit(1);
    }

    boolean verbose = cl.hasOption(O_VERBOSE);
    String bug = cl.getOptionValue(O_BUG);

    UpgradeOp upgradeOp = getUpgradeOp(bug, printer);
    upgradeOp.setVerbose(verbose);

    if (!upgradeOp.parseCommandLine(cl)) {
        System.exit(1);
    }

    upgradeOp.doUpgrade();

    printer.println("\n\n--------------");
    printer.println("done " + bug);
    printer.println("--------------");
}

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

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

    options.addOption(new Option(RANGE, "use range partitioner"));

    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("num").hasArg().withDescription("number of partitions")
            .create(NUM_PARTITIONS));

    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(NUM_PARTITIONS)) {
        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 inPath = cmdline.getOptionValue(INPUT);
    String outPath = cmdline.getOptionValue(OUTPUT);
    int nodeCount = Integer.parseInt(cmdline.getOptionValue(NUM_NODES));
    int numParts = Integer.parseInt(cmdline.getOptionValue(NUM_PARTITIONS));
    boolean useRange = cmdline.hasOption(RANGE);

    LOG.info("Tool name: " + PartitionGraph.class.getSimpleName());
    LOG.info(" - input dir: " + inPath);
    LOG.info(" - output dir: " + outPath);
    LOG.info(" - num partitions: " + numParts);
    LOG.info(" - node cnt: " + nodeCount);
    LOG.info(" - use range partitioner: " + useRange);

    Configuration conf = getConf();
    conf.setInt("NodeCount", nodeCount);

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

    job.setNumReduceTasks(numParts);

    FileInputFormat.setInputPaths(job, new Path(inPath));
    FileOutputFormat.setOutputPath(job, new Path(outPath));

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

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

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

    if (useRange) {
        job.setPartitionerClass(RangePartitioner.class);
    }

    FileSystem.get(conf).delete(new Path(outPath), true);

    job.waitForCompletion(true);

    return 0;
}

From source file:edu.umd.honghongie.PartitionGraph.java

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

    options.addOption(new Option(RANGE, "use range partitioner"));

    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("num").hasArg().withDescription("number of partitions")
            .create(NUM_PARTITIONS));

    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(NUM_PARTITIONS)) {
        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 inPath = cmdline.getOptionValue(INPUT);
    String outPath = cmdline.getOptionValue(OUTPUT);
    int nodeCount = Integer.parseInt(cmdline.getOptionValue(NUM_NODES));
    int numParts = Integer.parseInt(cmdline.getOptionValue(NUM_PARTITIONS));
    boolean useRange = cmdline.hasOption(RANGE);

    LOG.info("Tool name: " + PartitionGraph.class.getSimpleName());
    LOG.info(" - input dir: " + inPath);
    LOG.info(" - output dir: " + outPath);
    LOG.info(" - num partitions: " + numParts);
    LOG.info(" - node cnt: " + nodeCount);
    LOG.info(" - use range partitioner: " + useRange);

    Configuration conf = getConf();
    conf.setInt("NodeCount", nodeCount);

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

    job.setNumReduceTasks(numParts);

    FileInputFormat.setInputPaths(job, new Path(inPath));
    FileOutputFormat.setOutputPath(job, new Path(outPath));

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

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

    job.setOutputKeyClass(IntWritable.class);
    //  job.setOutputKeyClass(LongWritable.class);
    job.setOutputValueClass(PageRankNode.class);

    if (useRange) {
        job.setPartitionerClass(RangePartitioner.class);
    }

    FileSystem.get(conf).delete(new Path(outPath), true);

    job.waitForCompletion(true);

    return 0;
}

From source file:edu.osu.ling.pep.Pep.java

/**
 * Invokes Pep from the command line./*from   ww w. j av a  2s.  co m*/
 * <p>
 * The main work this method does, apart from tokenizing the arguments and
 * input tokens, is to load and parse the XML grammar file (as specified by
 * <code>-g</code> or <code>--grammar</code>). If any of the arguments
 * <code>-g</code>, <code>--grammar</code>, <code>-s</code>,
 * <code>--seed</code>, <code>-o</code>, <code>--option</code>, occur with
 * no argument following, this method prints an error notifying the user.
 * 
 * @param args
 *            The expected arguments are as follows, and can occur in any
 *            particular order:
 *            <ul>
 *            <li><code>-g|--grammar &lt;grammar file&gt;</code></li> <li>
 *            <code>-s|--seed &lt;seed category&gt;</code></li> <li><code>
 *            -v|--verbose {verbosity level}</code></li> <li><code>
 *            -o|--option &lt;OPTION_NAME=value&gt;</code></li> <li><code>
 *            -h|--help (prints usage information)</code></li> <li><code>
 *            &lt;token1 ... token<em>n</em>&gt;</code> (or <code>-</code>
 *            for standard input)</li>
 *            </ul>
 *            <code>OPTION_NAME</code> must be the name of one of the
 *            recognized {@link ParserOption options}. If <code>-h</code> or
 *            <code>--help</code> occur anywhere in the arguments, usage
 *            information is printed and no parsing takes place.
 */
@SuppressWarnings("static-access")
public static final void main(final String[] args) {
    try {
        final Options opts = new Options();

        opts.addOption(OptionBuilder.withLongOpt("grammar").withDescription("the grammar to use").hasArg()
                .isRequired().withArgName("grammar file").create('g'));

        opts.addOption(OptionBuilder.withLongOpt("seed").withDescription("the seed category to parse for")
                .hasArg().isRequired().withArgName("seed category").create('s'));

        opts.addOption(OptionBuilder.withLongOpt("verbose").withDescription("0-3").hasOptionalArg()
                .withArgName("verbosity level").create('v'));

        opts.addOption(OptionBuilder.withLongOpt("option").withDescription("sets parser options")
                .withArgName("OPTION=value").hasArgs(2).withValueSeparator()
                .withDescription("use value for given property").create("o"));

        opts.addOption(OptionBuilder.withLongOpt("help").withDescription("prints this message").create('h'));

        final CommandLineParser parser = new GnuParser();
        try {
            final CommandLine line = parser.parse(opts, args);
            if (line.hasOption('h')) {
                Pep.printHelp(opts);
            } else {
                final int v = Integer.parseInt(line.getOptionValue('v', Integer.toString(Pep.V_PARSE)));
                if (v < 0) {
                    throw new PepException("verbosity < 0: " + v);
                }

                Pep.verbosity = v;
                final Map<ParserOption, Boolean> options = new EnumMap<ParserOption, Boolean>(
                        ParserOption.class);

                final Properties props = line.getOptionProperties("o");
                for (final Object key : props.keySet()) {
                    try {
                        options.put(ParserOption.valueOf(key.toString()),
                                Boolean.valueOf(props.get(key).toString()));
                    } catch (final IllegalArgumentException iae) {
                        Pep.printError("no option named " + key.toString());
                        Pep.printHelp(opts);
                        return;
                    }
                }

                final Pep pep = new Pep(options);
                // final Grammar grammar =
                // new GrammarParser(Pep.findGrammar(line
                // .getOptionValue('g'))).t.parse();

                final List<?> ts = line.getArgList();
                List<String> tokens = null;
                if (ts.isEmpty() || ts.get(0).equals("-")) {
                    tokens = Pep.readTokens(new Scanner(System.in));
                } else {
                    tokens = new ArrayList<String>(ts.size());
                    for (final Object t : ts) {
                        tokens.add(t.toString());
                    }
                }

                pep.lastParseStart = System.currentTimeMillis();
                // try {
                // pep.parse(grammar, tokens,
                // new Category(line.getOptionValue('s')));
                // } catch (final PepException ignore) {
                // // ignore here, we're listening
                // }
            }
        } catch (final ParseException pe) {
            Pep.printError("command-line syntax problem: " + pe.getMessage());
            Pep.printHelp(opts);
        }
    } catch (final PepException pe) {
        final Throwable cause = pe.getCause();
        Pep.printError((cause == null) ? pe : cause);
    } catch (final RuntimeException re) {
        Pep.printError(re);
    }
}

From source file:ivory.app.PreprocessClueWebEnglish.java

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

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("(required) collection path")
            .create(PreprocessCollection.COLLECTION_PATH));
    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("(required) index path")
            .create(PreprocessCollection.INDEX_PATH));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("(required) segment").create(SEGMENT));

    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(PreprocessCollection.COLLECTION_PATH)
            || !cmdline.hasOption(PreprocessCollection.INDEX_PATH) || !cmdline.hasOption(SEGMENT)) {
        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 collection = cmdline.getOptionValue(PreprocessCollection.COLLECTION_PATH);
    String indexPath = cmdline.getOptionValue(PreprocessCollection.INDEX_PATH);
    int segment = Integer.parseInt(cmdline.getOptionValue(SEGMENT));

    LOG.info("Tool name: " + PreprocessClueWebEnglish.class.getSimpleName());
    LOG.info(" - collection path: " + collection);
    LOG.info(" - index path: " + indexPath);
    LOG.info(" - segement: " + segment);

    Configuration conf = getConf();
    FileSystem fs = FileSystem.get(conf);

    // Create the index directory if it doesn't already exist.
    Path p = new Path(indexPath);
    if (!fs.exists(p)) {
        LOG.info("index path doesn't exist, creating...");
        fs.mkdirs(p);
    } else {
        LOG.info("Index directory " + p + " already exists!");
        return -1;
    }

    RetrievalEnvironment env = new RetrievalEnvironment(indexPath, fs);
    Path mappingFile = env.getDocnoMappingData();
    new ClueWarcDocnoMappingBuilder().build(new Path(collection), mappingFile, conf);

    conf.set(Constants.CollectionName, "ClueWeb:English:Segment" + segment);
    conf.set(Constants.CollectionPath, collection);
    conf.set(Constants.IndexPath, indexPath);
    conf.set(Constants.InputFormat, SequenceFileInputFormat.class.getCanonicalName());
    conf.set(Constants.Tokenizer, GalagoTokenizer.class.getCanonicalName());
    conf.set(Constants.DocnoMappingClass, ClueWarcDocnoMapping.class.getCanonicalName());
    conf.set(Constants.DocnoMappingFile, env.getDocnoMappingData().toString());

    conf.setInt(Constants.DocnoOffset, DOCNO_OFFSETS[segment]);
    conf.setInt(Constants.MinDf, 10);
    conf.setInt(Constants.MaxDf, Integer.MAX_VALUE);

    new BuildTermDocVectors(conf).run();
    new ComputeGlobalTermStatistics(conf).run();
    new BuildDictionary(conf).run();
    new BuildIntDocVectors(conf).run();

    new BuildIntDocVectorsForwardIndex(conf).run();
    new BuildTermDocVectorsForwardIndex(conf).run();

    return 0;
}

From source file:edu.umd.cloud9.example.bfs.FindNodeAtDistance.java

@SuppressWarnings("static-access")
@Override/*from   ww w .j a v a  2 s .  c o  m*/
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 path").create(OUTPUT_OPTION));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("distance").create(DISTANCE_OPTION));

    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_OPTION)
            || !cmdline.hasOption(DISTANCE_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(this.getClass().getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
    }

    String inputPath = cmdline.getOptionValue(INPUT_OPTION);
    String outputPath = cmdline.getOptionValue(OUTPUT_OPTION);
    int distance = Integer.parseInt(cmdline.getOptionValue(DISTANCE_OPTION));

    LOG.info("Tool name: " + this.getClass().getName());
    LOG.info(" - inputDir: " + inputPath);
    LOG.info(" - outputDir: " + outputPath);
    LOG.info(" - distance: " + distance);

    Job job = new Job(getConf(), String.format("FindNodeAtDistance[%s: %s, %s: %s, %s: %d]", INPUT_OPTION,
            inputPath, OUTPUT_OPTION, outputPath, DISTANCE_OPTION, distance));
    job.setJarByClass(FindNodeAtDistance.class);

    job.setNumReduceTasks(0);

    job.getConfiguration().setInt(DISTANCE_OPTION, distance);
    job.getConfiguration().setInt("mapred.min.split.size", 1024 * 1024 * 1024);

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

    job.setInputFormatClass(SequenceFileInputFormat.class);
    job.setOutputFormatClass(TextOutputFormat.class);

    job.setMapOutputKeyClass(IntWritable.class);
    job.setMapOutputValueClass(BFSNode.class);
    job.setOutputKeyClass(IntWritable.class);
    job.setOutputValueClass(BFSNode.class);

    job.setMapperClass(MyMapper.class);

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

    job.waitForCompletion(true);

    return 0;
}

From source file:com.linkedin.databus.bootstrap.utils.BootstrapDBCleanerMain.java

@SuppressWarnings("static-access")
public static void parseArgs(String[] args) throws IOException {
    CommandLineParser cliParser = new GnuParser();

    Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen")
            .create(HELP_OPT_CHAR);/*from   w  ww .  j a  v a 2  s .  com*/

    Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME)
            .withDescription("Bootstrap Cleaner and DB properties to use").hasArg().withArgName("property_file")
            .create(BOOTSTRAP_DB_PROP_OPT_CHAR);

    Option cmdLinePropsOption1 = OptionBuilder.withLongOpt(CLEANER_CMD_LINE_PROPS_OPT_LONG_NAME)
            .withDescription("Cmd line override of cleaner config properties. Semicolon separated.").hasArg()
            .withArgName("Semicolon_separated_properties").create(CLEANER_CMD_LINE_PROPS_OPT_CHAR);

    Option log4jPropsOption = OptionBuilder.withLongOpt(LOG4J_PROPS_OPT_LONG_NAME)
            .withDescription("Log4j properties to use").hasArg().withArgName("property_file")
            .create(LOG4J_PROPS_OPT_CHAR);

    Option sourcesOption = OptionBuilder.withLongOpt(BOOTSTRAP_SOURCES_OPT_LONG_NAME)
            .withDescription(
                    "Comma seperated list of sourceNames. If not provided, no source will be cleaned up")
            .hasArg().withArgName("comma-seperated sources").create(BOOTSTRAP_SOURCES_PROP_OPT_CHAR);

    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(dbOption);
    options.addOption(cmdLinePropsOption1);
    options.addOption(log4jPropsOption);
    options.addOption(sourcesOption);

    CommandLine cmd = null;
    try {
        cmd = cliParser.parse(options, args);
    } catch (ParseException pe) {
        LOG.error("Bootstrap Physical Config: failed to parse command-line options.", pe);
        throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
    }

    if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR)) {
        String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
        PropertyConfigurator.configure(log4jPropFile);
        LOG.info("Using custom logging settings from file " + log4jPropFile);
    } else {
        PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
        ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);

        Logger.getRootLogger().removeAllAppenders();
        Logger.getRootLogger().addAppender(defaultAppender);

        LOG.info("Using default logging settings");
    }

    if (cmd.hasOption(HELP_OPT_CHAR)) {
        printCliHelp(options);
        System.exit(0);
    }

    if (cmd.hasOption(BOOTSTRAP_SOURCES_PROP_OPT_CHAR)) {
        _sSources = new ArrayList<String>();
        String srcListStr = cmd.getOptionValue(BOOTSTRAP_SOURCES_PROP_OPT_CHAR);
        LOG.info("Going to run cleaner for only these sources : " + srcListStr);
        String[] srcList = srcListStr.split(",");
        for (String s : srcList)
            _sSources.add(s);
    }

    if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR))
        throw new RuntimeException("Bootstrap config is not provided");

    String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
    LOG.info("Loading bootstrap DB config from properties file " + propFile);

    _sBootstrapConfigProps = new Properties();
    FileInputStream f = new FileInputStream(propFile);
    try {
        _sBootstrapConfigProps.load(f);
    } finally {
        f.close();
    }
    if (cmd.hasOption(CLEANER_CMD_LINE_PROPS_OPT_CHAR)) {
        String cmdLinePropString = cmd.getOptionValue(CLEANER_CMD_LINE_PROPS_OPT_CHAR);
        updatePropsFromCmdLine(_sBootstrapConfigProps, cmdLinePropString);
    }
}