Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.yammer.dropwizard.cli;
 
 
 @SuppressWarnings("UseOfSystemOutOrSystemErr")
 public class UsagePrinter {
     private UsagePrinter() {
        // singleton
    }
    public static void printRootHelp(AbstractService<?> service) {
        ..printf("java -jar %s <command> [arg1 arg2]\n\n"new JarLocation(service.getClass()));
        ..println("Commands");
        ..println("========\n");
        for (Command command : service.getCommands()) {
            printCommandHelp(commandservice.getClass());
        }
    }
    public static void printCommandHelp(Command cmdClass<?> klass) {
        printCommandHelp(cmdklassnull);
    }
    public static void printCommandHelp(Command cmdClass<?> klassString errorMessage) {
        if (errorMessage != null) {
            ..println(errorMessage);
            ..println();
        }
        ..println(formatTitle(cmd));
        final HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.setLongOptPrefix(" --");
        helpFormatter.printHelp(String.format("java -jar %s"cmd.getUsage(klass)),
                                cmd.getOptionsWithHelp());
        ..println("\n");
    }
    private static String formatTitle(Command cmd) {
        final String title = cmd.getName() + ": " + cmd.getDescription();
        return title + '\n' + getBanner(title.length());
    }
    private static String getBanner(int length) {
        final StringBuilder builder = new StringBuilder(length);
        for (int i = 0; i < lengthi++) {
            builder.append('-');
        }
        return builder.toString();
    }
New to GrepCode? Check out our FAQ X