Class HelpPrinter


  • public final class HelpPrinter
    extends java.lang.Object
    Generates and prints structured help output.
    • Constructor Summary

      Constructors 
      Constructor Description
      HelpPrinter​(java.lang.String name)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      HelpPrinter documentation​(java.lang.String documentation)
      Defines the optional long-form documentation that comes after long argument descriptions.
      static HelpPrinter fromArguments​(java.lang.String name, Arguments arguments)
      Create a HelpPrinter that registers help options and parameters defined in the given arguments.
      HelpPrinter maxWidth​(int maxWidth)  
      HelpPrinter option​(java.lang.String longName, java.lang.String shortName, java.lang.String description)
      Adds an option that takes no argument value.
      HelpPrinter param​(java.lang.String longName, java.lang.String shortName, java.lang.String exampleValue, java.lang.String description)
      Adds a parameter that requires an argument value.
      HelpPrinter positional​(java.lang.String name, java.lang.String description)
      Defines a positional argument.
      void print​(ColorFormatter colors, CliPrinter printer)
      Prints the generated help to the given printer.
      HelpPrinter summary​(java.lang.String summary)
      Defines the summary text of the command that comes after the short argument description and before the long argument descriptions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HelpPrinter

        public HelpPrinter​(java.lang.String name)
    • Method Detail

      • maxWidth

        public HelpPrinter maxWidth​(int maxWidth)
      • fromArguments

        public static HelpPrinter fromArguments​(java.lang.String name,
                                                Arguments arguments)
        Create a HelpPrinter that registers help options and parameters defined in the given arguments.
        Parameters:
        name - Name of the command.
        arguments - Arguments to extract params from.
        Returns:
        Returns the created HelpPrinter.
      • summary

        public HelpPrinter summary​(java.lang.String summary)
        Defines the summary text of the command that comes after the short argument description and before the long argument descriptions.
        Parameters:
        summary - Summary text to display.
        Returns:
        Returns the printer.
      • documentation

        public HelpPrinter documentation​(java.lang.String documentation)
        Defines the optional long-form documentation that comes after long argument descriptions.
        Parameters:
        documentation - Documentation to display.
        Returns:
        Returns the printer.
      • option

        public HelpPrinter option​(java.lang.String longName,
                                  java.lang.String shortName,
                                  java.lang.String description)
        Adds an option that takes no argument value.
        Parameters:
        longName - Nullable argument long form (e.g., "--foo").
        shortName - Nullable argument short form (e.g., null).
        description - Description description of the argument.
        Returns:
        Returns the printer.
      • param

        public HelpPrinter param​(java.lang.String longName,
                                 java.lang.String shortName,
                                 java.lang.String exampleValue,
                                 java.lang.String description)
        Adds a parameter that requires an argument value.
        Parameters:
        longName - Nullable argument long form (e.g., "--foo").
        shortName - Nullable argument short form (e.g., null).
        exampleValue - Example value of the parameter (e.g., "FOO").
        description - Description description of the argument.
        Returns:
        Returns the printer.
      • positional

        public HelpPrinter positional​(java.lang.String name,
                                      java.lang.String description)
        Defines a positional argument.
        Parameters:
        name - Name of the positional argument (e.g., <MODEL...>)
        description - Description of the argument.
        Returns:
        Returns the printer.
      • print

        public void print​(ColorFormatter colors,
                          CliPrinter printer)
        Prints the generated help to the given printer.
        Parameters:
        colors - Color formatter.
        printer - CliPrinter to write to.