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

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

Introduction

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

Prototype

public void setOptionComparator(Comparator comparator) 

Source Link

Document

Set the comparator used to sort the options when they output in help text Passing in a null parameter will set the ordering to the default mode

Usage

From source file:org.parallelj.launching.transport.tcp.command.AbstractLaunchTcpCommand.java

@Override
public String getHelp() {
    final Writer writer = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(writer);
    final Options options = new Options();
    for (IOption ioption : this.getOptions()) {
        options.addOption(ioption.getOption());
    }/*ww w.jav  a 2s .c om*/
    final HelpFormatter formatter = new HelpFormatter();
    formatter.setSyntaxPrefix("  ");
    final Comparator<Option> comparator = new Comparator<Option>() {
        public int compare(final Option option1, final Option option2) {
            if (option1.isRequired()) {
                return -1;
            }
            if (option2.isRequired()) {
                return 1;
            }
            return 0;
        }
    };
    formatter.setOptionComparator(comparator);
    printWriter.print(getUsage() + TcpIpHandlerAdapter.ENDLINE);
    formatter.printHelp(printWriter, DEFAULT_WIDTH, getType(), null, options, DEFAULT_LEFT_PAD,
            DEFAULT_DESC_PAD, null, true);
    printWriter.flush();
    try {
        writer.flush();
    } catch (IOException e) {
        LaunchingMessageKind.EREMOTE0009.format(e);
    }
    return writer.toString();
}

From source file:org.ppojo.HelpPrinter.java

public static void print(Options options) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setSyntaxPrefix("");
    formatter.setOptionComparator(Comparator.instance);
    formatter.setWidth(140);/*from   ww  w  . j  a va  2  s .co m*/
    formatter.printHelp("usage: papa-pojo -sources <sources folder> [options]", options);
}

From source file:org.psidnell.omnifocus.cli.ActiveOptionProcessor.java

@SuppressWarnings("unchecked")
public void printHelp() throws IOException {

    System.out.println(progName.toUpperCase());
    System.out.println();/*w  w  w .  ja  v a 2s .  c om*/

    try (InputStream in = this.getClass().getResourceAsStream("/version.properties")) {
        Properties p = new Properties();
        p.load(in);
        System.out.println("Version: " + p.getProperty("version"));
        System.out.println("Build Date: " + p.getProperty("date"));

    }

    System.out.println();

    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(200);
    // Output in the order I specify
    formatter
            .setOptionComparator((x, y) -> ((ActiveOption<P>) x).getOrder() - ((ActiveOption<P>) y).getOrder());
    formatter.printHelp(progName, options);
}

From source file:org.rapidcontext.app.Main.java

/**
 * Exits the application with optional help and/or error messages.
 * This method WILL NOT RETURN./*w  w  w .ja v  a  2 s. c  om*/
 *
 * @param options        the command-line options, or null
 * @param error          the error message, or null
 */
private static void exit(Options options, String error) {
    PrintWriter out = new PrintWriter(System.err);
    HelpFormatter fmt = new HelpFormatter();

    if (options != null) {
        out.println(USAGE);
        out.println();
        out.println("Options:");
        fmt.setOptionComparator(null);
        fmt.printOptions(out, 74, options, 2, 3);
        out.println();
    }
    if (error != null && error.length() > 0) {
        out.println("ERROR:");
        out.print("    ");
        out.println(error);
        out.println();
    }
    out.flush();
    System.exit(error == null ? 0 : 1);
}

From source file:org.semanticscience.PDBAptamerRetriever.main.RetrieveAptamers.java

private static void printUsage() {
    HelpFormatter hf = new HelpFormatter();
    hf.setOptionComparator(new Comparator() {
        private final String OPTS_ORDER = "helpgetallemmtcflrlffastaDirpdbDirpdbmlDirclickneedlegapOpengapExtend";

        public int compare(Object o1, Object o2) {
            Option opt1 = (Option) o1;
            Option opt2 = (Option) o2;
            return OPTS_ORDER.indexOf(opt1.getOpt()) - OPTS_ORDER.indexOf(opt2.getOpt());
        }//from  ww  w  .ja  v  a2 s .  co m
    });
    hf.printHelp("java -jar RetrieveAptamers.jar [OPTIONS]", createOptions());
}

From source file:PokemonGoMapValidator.Cli.java

private void help() {
    // This prints out some help
    HelpFormatter formater = new HelpFormatter();
    formater.setOptionComparator(null);
    formater.printHelp("Image Comparison", options);
    System.exit(0);//  w w  w . j a  v  a2s  .co m
}

From source file:scoutdoc.main.Main.java

private static void printHelpAndExit(Options options) {
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setWidth(200);//www  .  jav  a2 s.  c  o m
    helpFormatter.setOptionComparator(new Comparator<Option>() {

        @Override
        public int compare(Option opt1, Option opt2) {
            return ComparisonChain.start()
                    .compare(opt1.getOpt(), opt2.getOpt(),
                            Ordering.explicit(HELP_ID, PROP_ID, SOURCE_TASKS_ID, SOURCE_ALL_PAGES_ID,
                                    SOURCE_LIST_ID, SOURCE_RECENT_CHANGES_ID, SOURCE_RSS_ID, SOURCE_FILTER_ID,
                                    OPERATION_ID, OUTPUT_CHECKSTYLE_ID, OUTPUT_DASHBOARD_ID))
                    .result();
        }
    });
    helpFormatter.printHelp("scoutdoc.main.Main", options);
    System.exit(1);
}

From source file:se.trixon.filebydate.FileByDate.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);//ww  w .  j  a va  2s. co m

    HelpFormatter formatter = new HelpFormatter();
    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: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);/*ww w  .jav  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.jota.client.Main.java

private static void displayHelp(Options options) {
    String header = sBundle.getString("help_header");
    String footer = sBundle.getString("help_footer");

    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(null);
    formatter.printHelp("jotaclient", header, options, footer, true);
}