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:se.trixon.idxf.Main.java

private void displayHelp() {
    PrintStream defaultStdOut = System.out;
    StringBuilder sb = new StringBuilder().append(mBundle.getString("usage")).append("\n\n");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    System.setOut(ps);/*from  ww  w  . ja  v  a 2 s.c om*/

    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(79);
    formatter.setOptionComparator(null);
    formatter.printHelp("xxx", mOptions, false);
    System.out.flush();
    System.setOut(defaultStdOut);
    sb.append(baos.toString().replace("usage: xxx" + System.lineSeparator(), "")).append("\n")
            .append(IddHelper.getBundle().getString("help_footer"));

    System.out.println(sb.toString());
}

From source file:se.trixon.mapollage.Mapollage.java

public static String getHelp() {
    PrintStream defaultStdOut = System.out;
    StringBuilder sb = new StringBuilder().append(sBundle.getString("usage")).append("\n\n");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    System.setOut(ps);/*from w w  w. ja v a 2  s .  c  o m*/

    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(79);
    formatter.setOptionComparator(null);
    formatter.printHelp("xxx", sOptions, false);
    System.out.flush();
    System.setOut(defaultStdOut);
    sb.append(baos.toString().replace("usage: xxx" + System.lineSeparator(), "")).append("\n")
            .append(sBundle.getString("help_footer"));

    return sb.toString();
}

From source file:sourcefiles.BuildPageRankRecords.java

/**
 * Runs this tool./*www.j  a v  a2  s .  co  m*/
 */
@Override
@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));

    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)) {
        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));

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

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

    Job job = Job.getInstance(conf);
    job.setJobName(BuildPageRankRecords.class.getSimpleName() + ":" + inputPath);
    job.setJarByClass(BuildPageRankRecords.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(Text.class);
    job.setMapOutputValueClass(PageRankNode.class);

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(PageRankNode.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:sourcefiles.BuildPersonalizedPageRankRecords.java

/**
 * Runs this tool.//ww w . jav  a  2 s .co  m
 */
@Override
@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("path").hasArg().withDescription("sources").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)) {
        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(NODE_SRC_FIELD, 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.setOutputFormatClass(TextOutputFormat.class);

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(PageRankNodeEnhanced.class);

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(PageRankNodeEnhanced.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:sourcefiles.DumpPageRankRecordsToPlainText.java

/**
 * Runs this tool.//from w  w  w .ja v  a  2 s .c  o  m
 */
@Override
@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));

    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);

    LOG.info("Tool name: " + DumpPageRankRecordsToPlainText.class.getSimpleName());
    LOG.info(" - input: " + inputPath);
    LOG.info(" - output: " + outputPath);

    Configuration conf = new Configuration();
    conf.setInt("mapred.min.split.size", 1024 * 1024 * 1024);

    Job job = Job.getInstance(conf);
    job.setJobName(DumpPageRankRecordsToPlainText.class.getSimpleName());
    job.setJarByClass(DumpPageRankRecordsToPlainText.class);

    job.setNumReduceTasks(0);

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

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

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(PageRankNode.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:sourcefiles.PartitionGraph.java

/**
 * Runs this tool./*ww  w . j  av a 2 s.  co  m*/
 */
@Override
@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(Text.class);
    job.setMapOutputValueClass(PageRankNodeEnhanced.class);

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

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

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

    job.waitForCompletion(true);

    return 0;
}

From source file:sourcefiles.RunPageRankBasic.java

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

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("base path").create(BASE));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("start iteration").create(START));
    options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("end iteration").create(END));
    options.addOption(
            OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES));

    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(BASE) || !cmdline.hasOption(START) || !cmdline.hasOption(END)
            || !cmdline.hasOption(NUM_NODES)) {
        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 basePath = cmdline.getOptionValue(BASE);
    int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES));
    int s = Integer.parseInt(cmdline.getOptionValue(START));
    int e = Integer.parseInt(cmdline.getOptionValue(END));

    LOG.info("Tool name: RunPageRank");
    LOG.info(" - base path: " + basePath);
    LOG.info(" - num nodes: " + n);
    LOG.info(" - start iteration: " + s);
    LOG.info(" - end iteration: " + e);

    // Iterate PageRank.
    for (int i = s; i < e; i++) {
        iteratePageRank(i, i + 1, basePath, n);
    }

    return 0;
}

From source file:stone.sample.DecodeTool.java

private static void usage(CommandLine commandLine) {

    // load basicOptions
    _Options();/*  w w  w .  j  av  a2s.  c om*/
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(120);

    // print out license info prior to formatter.
    System.out.println("Apktool v" + _getVersion() + " - a tool for reengineering Android apk files\n" +
    // "with smali v" + ApktoolProperties.get("smaliVersion") +
    //  " and baksmali v" + ApktoolProperties.get("baksmaliVersion") + "\n" +
            "Copyright 2016 Sidney <sidney9111@gmail.com>\n" + "");
    formatter.printHelp("apktool ", allOptions);
    formatter.printHelp("apktool g", allOptions);

}

From source file:sw.main.Main.java

public static void main(String[] args) {

    //      args = new String[]{
    ////            "-h",
    //            "-i", "/home/steven/workspace/SF-ABC/Simulations/test/test.nex",
    //            "-t", "3", "400",
    //            "-m", "100000", "10000", "100",
    ////            "-Xe", "0.5",
    ////            "-Xm", "1e-5",
    ////            "-Xp", "5000",
    ////            "-Xm", "5e-6",
    ////            "-Xp", "20000",
    //      };//from   w w  w. j a v a 2  s.c  o m
    //      

    Options options = new Options();
    Option help = new Option("h", "help", false, "print this message");
    Option version = new Option("v", "version", false, "print the version information and exit");
    options.addOption(help);
    options.addOption(version);

    options.addOption(Option.builder("i").longOpt("infile").hasArg().argName("infile")
            .desc("REQUIRED: Infile (nexus format)").build());
    //      options.addOption(Option.builder("t").longOpt("time").hasArg()
    //            .argName("TIME").desc("Number of time points")
    //            .build());
    //      
    //      options.addOption(Option.builder("g").longOpt("gap").hasArg()
    //            .argName("GAP").desc("Time between gaps")
    //            .build());

    Builder C = Option.builder("m").longOpt("mcmc").numberOfArgs(3).argName("preprocess mcmc sampling")
            .desc("REQUIRED: Three Parameters in the following orders: " + "(1) Length of preprocessing, "
                    + "(2) Length of MCMC chain, " + "(3) Sample every n iterations.");
    options.addOption(C.build());

    C = Option.builder("t").longOpt("time").numberOfArgs(2).argName("numTime interval")
            .desc("REQUIRED: Two Parameters in the following orders: " + "(1) Number of time points, "
                    + "(2) Interval between two time points. ");
    options.addOption(C.build());

    //      options.addOption(Option.builder("Xe").longOpt("error").hasArg()
    //            .argName("error").desc("Error threshold for ABC.")
    //            .build());
    options.addOption(Option.builder("Xm").longOpt("mutation").hasArg().argName("mu")
            .desc("Initial mutation rate. [default: 0.00001]").build());
    options.addOption(Option.builder("Xp").longOpt("population").hasArg().argName("pop")
            .desc("Initial population size. [default: 5000]").build());

    HelpFormatter formatter = new HelpFormatter();
    String syntax = "sfabc -i <infile> -m <preprocess mcmc sampling> -t <numTime interval>";
    String header = "\nEstimation of evolutionary parameters using short, random and partial sequences from mixed samples of anonymous individuals. "
            + "\n\nArguments:\n";
    String footer = "\n";

    formatter.setWidth(80);

    Setting setting = null;

    try {
        CommandLineParser parser = new DefaultParser();
        CommandLine cmd = parser.parse(options, args);
        String[] pct_config = cmd.getArgs();

        if (cmd.hasOption("h") || args.length == 0) {
            formatter.printHelp(syntax, header, options, footer, false);
            System.exit(0);
        }
        if (cmd.hasOption("v")) {
            System.out.println("SF_ABC " + VERSION);
            System.exit(0);
        }
        if (pct_config.length != 0) {
            System.out.println(
                    "Warning! " + pct_config.length + " unused parameters: " + Arrays.toString(pct_config));
        }

        if (cmd.hasOption("infile")) {

            String obsDataName = cmd.getOptionValue("infile");
            setting = new Setting(obsDataName);

            NexusImporter imp = new NexusImporter(new FileReader(setting.getDataFile()));
            Alignment jeblAlignment = imp.importAlignments().get(0);
            int seqLength = jeblAlignment.getPatternCount();
            int totalSeqCount = jeblAlignment.getPatternLength();
            setting.setSeqInfo(seqLength, totalSeqCount);
            //            System.out.println("Infile: "+obsDataName);
        } else {
            System.out.println("Error! Input file (-i, --infile) required\n");
            System.exit(6);
        }

        if (cmd.hasOption("mcmc")) {
            String[] configs = cmd.getOptionValues("mcmc");

            int numItePreprocess = Integer.parseInt(configs[0]);
            int numIteMCMC = Integer.parseInt(configs[1]);
            int numIteSample = Integer.parseInt(configs[2]);
            setting.setMCMCSetting(numItePreprocess, numIteMCMC, numIteSample);
            //            System.out.println("MCMC: "+ numItePreprocess +"\t"+ numIteMCMC +"\t"+ numIteSample);
        } else {
            System.out.println("Error! MCMC (-m, --mcmc) options required\n");
            System.exit(6);
        }

        if (cmd.hasOption("time")) {
            String[] configs = cmd.getOptionValues("time");
            int numTimePoints = Integer.parseInt(configs[0]);
            int intervalBetweenTime = Integer.parseInt(configs[1]);

            setting.setTime(numTimePoints, intervalBetweenTime);
            //            System.out.println("Number of time points: "+numTimePoints);
        } else {
            System.out.println("Error! time (-t, --time) options required\n");
            System.exit(6);
        }

        //         if(cmd.hasOption("-Xe")){
        //            String s = cmd.getOptionValue("Xe");
        //            double error = Double.parseDouble(s);
        //            setting.setErrors(error);
        //         }

        if (cmd.hasOption("-Xm")) {
            String s = cmd.getOptionValue("Xm");
            double value = Double.parseDouble(s);
            setting.setInitValue(MU, value);
        }
        if (cmd.hasOption("-Xp")) {
            String s = cmd.getOptionValue("Xp");
            double value = Double.parseDouble(s);
            setting.setInitValue(POP, value);
        }

    } catch (ParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ImportException e) {
        e.printStackTrace();
    }

    startSimulation(setting);

}

From source file:synapticloop.gradle.plugin.create.Main.java

public static void main(String[] args) throws synapticloop.templar.exception.ParseException, RenderException {
    try {// www  . j av  a 2s .c om
        parseOptions(args);
    } catch (ParseException ex) {
        System.out.println("[FATAL] \n\t" + ex.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp("gradle-plugin-java-create", options);
        return;
    }

    // else we are good to go

    // the first thing we are going to do is to create the directories
    File propertiesDirectory = new File("./src/main/resources/META-INF/gradle-plugins/");
    propertiesDirectory.mkdirs();

    File javaSourceDirectory = new File("./src/main/java/" + javaPackage.replace(".", "/"));
    javaSourceDirectory.mkdirs();

    TemplarContext templarContext = new TemplarContext();
    templarContext.add("artefact", artefact);
    templarContext.add("description", desc);
    templarContext.add("displayGroup", displayGroup);
    templarContext.add("displayName", displayName);
    templarContext.add("javaPackage", javaPackage);

    templarContext.add("name", name);
    String lowerName = name.substring(0, 1).toLowerCase() + name.substring(1);
    templarContext.add("lowerName", lowerName);

    templarContext.add("tags", tags);

    // now create the properties file
    render(Main.class.getResourceAsStream("/META-INF/gradle-plugins/plugin.properties.templar"),
            new File(propertiesDirectory.getAbsolutePath() + "/" + artefact + "." + lowerName + ".properties"),
            templarContext);

    // now for the Plugin
    render(Main.class.getResourceAsStream("/plugin.java.templar"),
            new File(javaSourceDirectory.getAbsolutePath() + "/" + name + "Plugin.java"), templarContext);

    // now for the PluginExtension
    render(Main.class.getResourceAsStream("/pluginextension.java.templar"),
            new File(javaSourceDirectory.getAbsolutePath() + "/" + name + "PluginExtension.java"),
            templarContext);

    // now for the Plugin task
    render(Main.class.getResourceAsStream("/task.java.templar"),
            new File(javaSourceDirectory.getAbsolutePath() + "/" + name + "Task.java"), templarContext);

    // now for the Plugin task
    render(Main.class.getResourceAsStream("/build.plugin.gradle.templar"), new File("./build.plugin.gradle"),
            templarContext);

    // now for the Plugin task
    render(Main.class.getResourceAsStream("/build.plugin.initial.gradle.templar"),
            new File("./build.plugin.initial.gradle"), templarContext);
}