Example usage for org.apache.commons.cli HelpFormatter setWidth

List of usage examples for org.apache.commons.cli HelpFormatter setWidth

Introduction

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

Prototype

public void setWidth(int width) 

Source Link

Document

Sets the 'width'.

Usage

From source file:com.opengamma.integration.tool.config.ConfigImportExportTool.java

@Override
protected void usage(Options options) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(120);
    formatter.printHelp("config-import-export-tool.sh [file...]", options, true);
}

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

/**
 * Runs this tool.// w  w w .ja v a2  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:ivory.app.PreprocessClueWebEnglish.java

/**
 * Runs this tool./*from  w  w  w. j  a va 2 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:net.mitnet.tools.pdf.book.pdf.builder.ui.cli.PdfBookBuilderCLI.java

private void showHelp() {
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setWidth(CLI_USAGE_HELP_WIDTH);
    helpFormatter.printHelp(CLI_USAGE, CLI_HEADER, CLI_OPTIONS, CLI_FOOTER);
    System.exit(SystemExitValues.EXIT_CODE_TOO_FEW_ARGS);
}

From source file:edu.umd.cloud9.example.bigram.BigramCount.java

/**
 * Runs this tool.//w w w.  j av  a  2 s .c  om
 */
@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 reducers")
            .create(NUM_REDUCERS));

    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)) {
        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 reduceTasks = cmdline.hasOption(NUM_REDUCERS) ? Integer.parseInt(cmdline.getOptionValue(NUM_REDUCERS))
            : 1;

    LOG.info("Tool name: " + BigramCount.class.getSimpleName());
    LOG.info(" - input path: " + inputPath);
    LOG.info(" - output path: " + outputPath);
    LOG.info(" - num reducers: " + reduceTasks);

    Job job = Job.getInstance(getConf());
    job.setJobName(BigramCount.class.getSimpleName());
    job.setJarByClass(BigramCount.class);

    job.setNumReduceTasks(reduceTasks);

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

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(IntWritable.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);

    job.setMapperClass(MyMapper.class);
    job.setCombinerClass(MyReducer.class);
    job.setReducerClass(MyReducer.class);

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

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

    return 0;
}

From source file:ctmetrics.CTmetrics.java

private boolean parseArgs(String[] args) {

    // 1. Setup command line options
    Options options = new Options();
    options.addOption("h", "help", false, "Print this message");
    options.addOption("x", "debug", false, "debug mode" + ", default: " + debug);
    options.addOption("z", "zip", false, "zip mode" + ", default: " + zipmode);
    options.addOption("i", "individualSources", false, "monitor sources individually");

    options.addOption(Option.builder("b").argName("diskBlockSize").hasArg().desc(
            "disk block size (bytes), used for calculating DiskSize, default: " + diskBlockSize + " bytes")
            .build());// www . j  ava2s .co m
    options.addOption(Option.builder("o").argName("metricsFolder").hasArg()
            .desc("name of output folder" + ", default: " + metricsSource).build());
    options.addOption(Option.builder("T").argName("timePerBlock").hasArg()
            .desc("time per output block (sec)" + ", default: " + timePerBlock).build());
    options.addOption(Option.builder("t").argName("timePerSample").hasArg()
            .desc("time per sample (sec)" + ", default: " + timePerSample).build());
    options.addOption(Option.builder("r").argName("ringBuffer").hasArg()
            .desc("ring-buffer trim duration (sec), 0 to disable" + ", default: " + timePerLoop).build());
    options.addOption(Option.builder("s").argName("blocksPerSegment").hasArg()
            .desc("segment size (blocks), 0 to disable" + ", default: " + blocksPerSegment).build());

    // 2. Parse command line options
    CommandLineParser parser = new DefaultParser();
    CommandLine line = null;
    try {
        line = parser.parse(options, args);
    } catch (ParseException exp) { // oops, something went wrong
        System.err.println("Command line argument parsing failed: " + exp.getMessage());
        return false;
    }

    // 3. Retrieve the command line values
    String extraArgs[] = line.getArgs();
    if (extraArgs != null && extraArgs.length > 0)
        monitorFolder = extraArgs[0];

    if (line.hasOption("help")) { // Display help message and quit
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp("CTmetrics [options] sourceFolder (default: " + monitorFolder + ")\noptions: ",
                options);
        return false;
    }

    debug = line.hasOption("debug");
    zipmode = line.hasOption("zip") ? (!zipmode) : zipmode; // toggles default
    individualSources = line.hasOption("individualSources");

    diskBlockSize = Integer.parseInt(line.getOptionValue("b", "" + diskBlockSize));
    metricsSource = line.getOptionValue("o", metricsSource);
    timePerBlock = Double.parseDouble(line.getOptionValue("T", "" + timePerBlock));
    timePerSample = Double.parseDouble(line.getOptionValue("t", "" + timePerSample));
    timePerLoop = Double.parseDouble(line.getOptionValue("r", "" + timePerLoop));
    blocksPerSegment = Long.parseLong(line.getOptionValue("s", "" + blocksPerSegment));

    return true; // OK to go
}

From source file:com.linkedin.databus2.core.schema.tools.AvroConvertMain.java

public void printUsage() {
    HelpFormatter help = new HelpFormatter();
    help.setWidth(100);
    help.printHelp("java " + AvroConvertMain.class.getName() + " [options]", _options);
}

From source file:com.netflix.cc.cli.CmdLineParametersParser.java

/**
 * Parses cmd line arguments./*from   w w w  .java  2 s.c  om*/
 *
 * @param args arguments from a command line
 * @return a command line parameter object or null if help was invoked.
 */
public CmdLineParameters parseCmdOptions(String[] args) throws ParseException {
    // create the parser
    CommandLineParser parser = new DefaultParser();
    CommandLine line = parser.parse(options, args);

    // --help
    if (line.hasOption(help.getLongOpt())) {
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp("ttml-to-stl", options);
        return null;
    }

    CmdLineParameters result = new CmdLineParameters();
    // --ttml parameters
    for (Option option : line.getOptions()) {
        if (option.equals(ttmlFile)) {
            TtmlInDescriptor ttmlInDescriptor = new TtmlInDescriptor();
            try {
                ttmlInDescriptor.setFile(option.getValue(0));
                ttmlInDescriptor.setOffsetMS(parseTtmlParameter(option, 1, "offsetMS"));
                ttmlInDescriptor.setStartMS(parseTtmlParameter(option, 2, "startMS"));
                ttmlInDescriptor.setEndMS(parseTtmlParameter(option, 3, "endMS"));
            } catch (IndexOutOfBoundsException e) {
                //It is error only if don't have file name
                //For required file it may not be thrown. We will check it later.
            }

            if (ttmlInDescriptor.getFile() == null) {
                throw new ParseException("--ttml parameter must have at least <file> attribute defined.");
            }

            result.getTtmlInDescriptors().add(ttmlInDescriptor);
        }
    }
    if (result.getTtmlInDescriptors().isEmpty()) {
        throw new ParseException("At least one input TTML file must be provided");
    }

    // TTML mode parameters
    boolean doOutputTTML = line.hasOption(outputTtml.getLongOpt());
    if (doOutputTTML) {
        result.setDoOuputTtml(true);
        result.setOutputTtmlFile(line.getOptionValue(outputTtml.getLongOpt()));
    }

    // SCC mode parameters
    boolean doOutputScc = line.hasOption(outputScc.getLongOpt());
    if (doOutputScc) {
        result.setDoOutputScc(true);
        result.setOutputSccFile(line.getOptionValue(outputScc.getLongOpt()));
    }

    return result;
}

From source file:code.DemoWordCount.java

/**
 * Runs this tool./*from  w  w w  . j a v  a  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 reducers")
            .create(NUM_REDUCERS));

    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)) {
        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 reduceTasks = cmdline.hasOption(NUM_REDUCERS) ? Integer.parseInt(cmdline.getOptionValue(NUM_REDUCERS))
            : 1;

    LOG.info("Tool: " + DemoWordCount.class.getSimpleName());
    LOG.info(" - input path: " + inputPath);
    LOG.info(" - output path: " + outputPath);
    LOG.info(" - number of reducers: " + reduceTasks);

    Configuration conf = getConf();
    Job job = Job.getInstance(conf);
    job.setJobName(DemoWordCount.class.getSimpleName());
    job.setJarByClass(DemoWordCount.class);

    job.setNumReduceTasks(reduceTasks);

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

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

    job.setMapperClass(MyMapper.class);
    job.setCombinerClass(MyReducer.class);
    job.setReducerClass(MyReducer.class);

    // Delete the output directory if it exists already.
    Path outputDir = new Path(outputPath);
    FileSystem.get(conf).delete(outputDir, 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.netflix.subtitles.cli.TtmlConverterCmdLineParser.java

/**
 * Parses command line./*  w w  w .  ja  v  a  2s. c  o m*/
 *
 * @param args cli arguments
 * @return parsed parameters object
 * @throws ParseException
 */
public TtmlConverterCmdLineParams parse(String[] args) throws ParseException {
    TtmlConverterCmdLineParams params = new TtmlConverterCmdLineParams();

    CommandLineParser parser = new DefaultParser();
    CommandLine line;
    try {
        line = parser.parse(options, args);
    } catch (org.apache.commons.cli.ParseException e) {
        throw new ParseException(e);
    }

    // help
    if (line.hasOption(help.getOpt())) {
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp("ttml2stl", options);

        return null;
    }

    // outputFile
    if (line.hasOption(out.getOpt())) {
        params.setOutputFile(line.getOptionValue(out.getOpt()));
    } else {
        throw new ParseException("Output file option must be provided.");
    }

    // frameRate
    if (line.hasOption(frameRate.getOpt())) {
        params.setFrameRate(parseFrameRate(line.getOptionValue(frameRate.getOpt())));
    }

    // ttml
    params.getTtmlOptions().addAll(Stream.of(line.getOptions()).filter((o) -> o.equals(ttml)).map((o) -> {
        TtmlOption ttmlOption = new TtmlOption();

        try {
            ttmlOption.setFileName(o.getValue(0));
            ttmlOption.setOffsetMS(parseTtmlParameter(o, 1, "offsetMS"));
            ttmlOption.setStartMS(parseTtmlParameter(o, 2, "startMS"));
            ttmlOption.setEndMS(parseTtmlParameter(o, 3, "endMS"));
        } catch (IndexOutOfBoundsException e) {
            //It is error only if don't have file name
            //For required file it may not be thrown. We will check it later.
        }

        if (ttmlOption.getFileName() == null) {
            throw new ParseException("--ttml parameter must have at least <file> attribute defined.");
        }

        return ttmlOption;
    }).collect(Collectors.toCollection(ArrayList::new)));
    if (params.getTtmlOptions().isEmpty()) {
        throw new ParseException("At least one input TTML file must be provided.");
    }

    return params;
}