Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.selesse.jxlint.cli;
Generator of org.apache.commons.cli.Options and its Comparator. These options are jxlint's defaults, but can be extended.
 public class CommandLineOptions {
Populate the org.apache.commons.cli.Options for our command line parser. This sets up all the option short names, long names, and help messages. It can also specify whether the argument takes arguments (i.e. "--html index.html"), and whether options are mutually exclusive.
     public static Options generateJxlintOptions() {
         Options options = new Options();
         // The sequence in which these options are added represents the order in which we want them to be displayed.
         // If this order is modified, make sure to modify "CommandLineOptions.getOptionsOrder".
         options.addOption("h""help"false"Usage information, help message.");
         options.addOption("v""version"false"Output version information.");
         options.addOption("p""profile"false"Measure time every rule takes to complete.");
         options.addOption("l""list"false"Lists lint rules with a short, summary explanation.");
         options.addOption("b""web"false"Run in the background, as a website.");
                 withDescription("Run in the background, as a website. " +
                         "(default port: " + . + ")").
         options.addOption("r""rules"false"Prints a Markdown dump of the program's rules.");
                 withDescription("Lists a verbose rule explanation.").
                 withDescription("Only check for these rules.").
                 withDescription("Disable the list of rules.").
                 withDescription("Enable the list of rules.").
                         withDescription("Run all rules of a certain category.").
         options.addOption("w""nowarn"false"Only check for errors; ignore warnings.");
         options.addOption("Wall""Wall"false"Check all warnings, including those off by default.");
         options.addOption("Werror""Werror"false"Treat all warnings as errors.");
         OptionGroup outputOptionGroup = new OptionGroup();
                 withDescription("Don't output any progress or reports.").
                 withDescription("Create an HTML report.").
                 withDescription("Create an XML (!!) report.").
         return options;

Return the command line's help message based on the org.apache.commons.cli.Options created in generateJxlintOptions().
     public static String getHelpMessage(ProgramSettings programSettings) {
         HelpFormatter helpFormatter = new HelpFormatter();
        StringBuilder exitStatusFooter = new StringBuilder("<RULE[s]> should be comma separated, without spaces.\n");
        exitStatusFooter.append("Exit Status:\n");
        for (ExitType exitType : ExitType.values()) {
            exitStatusFooter.append(String.format("%-21d %-30s%n"exitType.getErrorCode(), exitType.getExplanation()));
        String outputString = "";
        // redirect stdout to a temporary stream to capture HelpFormatter.printHelp()
        PrintStream previousOut = .;
        try {
            final ByteArrayOutputStream output = new ByteArrayOutputStream();
            System.setOut(new PrintStream(outputtrue..displayName()));
            helpFormatter.printHelp(programSettings.getProgramName() + " [flags] <directory>""",
                    generateJxlintOptions(), "\n" + exitStatusFooter.toString().trim());
            outputString = output.toString(..displayName());
        catch (UnsupportedEncodingException e) {
            // nothing to do here, why wouldn't UTF-8 be available?
        finally {
        return outputString;

Our desired options order. This gives us control on how our help gets printed, via optionsOrdering.
    private static String getOptionsOrder() {
        return "hvplbrscdeywWallWerrorqtx";

Ordering that will return options in the order they appear in getOptionsOrder() first.
    private static final Ordering<OptionoptionsOrdering = new Ordering<Option>() {
        public int compare(Option o1Option o2) {
            return getOptionsOrder().indexOf(o1.getOpt()) - getOptionsOrder().indexOf(o2.getOpt());
New to GrepCode? Check out our FAQ X