Class ManPageGenerator

  • All Implemented Interfaces:
    java.util.concurrent.Callable<java.lang.Integer>

    public class ManPageGenerator
    extends java.lang.Object
    implements java.util.concurrent.Callable<java.lang.Integer>
    Generates AsciiDoc files in a special format that can be converted to HTML, PDF and Unix Man pages.

    This class can be used as a subcommand, in which case it generates man pages for all non-hidden commands in the hierarchy from the top-level command down, or it can be executed as a stand-alone tool, in which case the user needs to specify the @Command-annotated classes to generate man pages for.

    • Constructor Detail

      • ManPageGenerator

        public ManPageGenerator()
    • Method Detail

      • call

        public java.lang.Integer call()
                               throws java.io.IOException
        Invokes generateManPage(Config, CommandLine.Model.CommandSpec...) to generate man pages for all non-hidden commands in the hierarchy from the top-level command down. This method is only called when this class is used as a subcommand.
        Specified by:
        call in interface java.util.concurrent.Callable<java.lang.Integer>
        Returns:
        an exit code indicating success or failure, as follows:
        • 0: Successful program execution.
        • 1: A runtime exception occurred while generating man pages.
        • 2: Usage error: user input for the command was incorrect, e.g., the wrong number of arguments, a bad flag, a bad syntax in a parameter, etc.
        • 4: A template file exists in the template directory. (Remove the `--template-dir` option or use `--force` to overwrite.)
        Throws:
        java.io.IOException - if a problem occurred writing files.
      • main

        public static void main​(java.lang.String[] args)
        Invokes generateManPage(Config, CommandLine.Model.CommandSpec...) to generate man pages for the user-specified @Command-annotated classes.

        If the --exit option is specified, System.exit is invoked afterwards with an exit code as follows:

        • 0: Successful program execution.
        • 1: A runtime exception occurred while generating man pages.
        • 2: Usage error: user input for the command was incorrect, e.g., the wrong number of arguments, a bad flag, a bad syntax in a parameter, etc.
        • 4: A template file exists in the template directory. (Remove the `--template-dir` option or use `--force` to overwrite.)
        Parameters:
        args - command line arguments to be parsed. Must include the classes to generate man pages for.
      • generateManPage

        public static int generateManPage​(java.io.File outdir,
                                          java.io.File customizablePagesDirectory,
                                          boolean[] verbosity,
                                          boolean overwriteCustomizablePages,
                                          CommandLine.Model.CommandSpec... specs)
                                   throws java.io.IOException
        Generates AsciiDoc files for the specified classes to the specified output directory, optionally also generating template files in the customizablePagesDirectory directory.
        Parameters:
        outdir - Output directory to write the generated AsciiDoc files to.
        customizablePagesDirectory - Optional directory to write customizable man page template files. If non-null, an additional "template" file is created here for each generated manpage AsciiDoc file.
        verbosity - the length of this array determines verbosity during processing
        overwriteCustomizablePages - Overwrite existing man page templates. The default is false, meaning processing is aborted and the process exits with status code 4 if a man page template file already exists.
        specs - the Commands to generate AsciiDoc man pages for
        Returns:
        the exit code
        Throws:
        java.io.IOException - if a problem occurred writing to the file system