Package picocli.codegen.docgen.manpage
Class ManPageGenerator
- java.lang.Object
-
- picocli.codegen.docgen.manpage.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classManPageGenerator.App(package private) static classManPageGenerator.Config(package private) static classManPageGenerator.ShortestFirstSorts short strings before longer strings.(package private) static classManPageGenerator.SortByOrder<T extends CommandLine.Model.IOrdered>(package private) static classManPageGenerator.SortByShortestOptionNameAlphabeticallySortsOptionSpecinstances by their name in case-insensitive alphabetic order.
-
Field Summary
Fields Modifier and Type Field Description (package private) static CommandLine.Help.Ansi.IStyleBOLD(package private) static CommandLine.Help.ColorSchemeCOLOR_SCHEME(package private) ManPageGenerator.Configconfig(package private) static intEXIT_CODE_TEMPLATE_EXISTS(package private) static CommandLine.Help.Ansi.IStyleHIGHLIGHT(package private) static CommandLine.Help.Ansi.IStyleITALIC(package private) CommandLine.Model.CommandSpecspec
-
Constructor Summary
Constructors Constructor Description ManPageGenerator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Integercall()InvokesgenerateManPage(Config, CommandLine.Model.CommandSpec...)to generate man pages for all non-hidden commands in the hierarchy from the top-level command down.private static java.util.Map<java.lang.String,CommandLine.Help.Ansi.IStyle>createMarkupMap()private static java.util.Comparator<CommandLine.Model.OptionSpec>createOrderComparatorIfNecessary(java.util.List<CommandLine.Model.OptionSpec> options)private static booleanempty(java.lang.Object[] array)private static java.lang.StringfirstElement(java.lang.String[] elements)(package private) static voidgenCommands(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)private static intgenerateCustomizableTemplate(ManPageGenerator.Config config, CommandLine.Model.CommandSpec spec)static intgenerateManPage(java.io.File outdir, java.io.File customizablePagesDirectory, boolean[] verbosity, boolean overwriteCustomizablePages, CommandLine.Model.CommandSpec... specs)Generates AsciiDoc files for the specified classes to the specified output directory, optionally also generating template files in thecustomizablePagesDirectorydirectory.(package private) static intgenerateManPage(ManPageGenerator.Config config, CommandLine.Model.CommandSpec... specs)private static intgenerateSingleManPage(ManPageGenerator.Config config, CommandLine.Model.CommandSpec spec)private static voidgenerateSingleManPage(CommandLine.Model.CommandSpec spec, java.io.File manpage)(package private) static voidgenExitStatus(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)(package private) static voidgenFooter(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)(package private) static voidgenHeader(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)(package private) static voidgenOptions(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)(package private) static voidgenPositionalArgs(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)private static java.lang.StringheaderDescriptionString(CommandLine.Model.CommandSpec spec)private static java.lang.Stringjoin(java.lang.String sep, java.lang.Object... lines)static voidmain(java.lang.String[] args)InvokesgenerateManPage(Config, CommandLine.Model.CommandSpec...)to generate man pages for the user-specified@Command-annotated classes.private static java.lang.StringmakeFileName(CommandLine.Model.CommandSpec spec)private static java.lang.StringmakeHeading(java.lang.String heading, java.lang.String defaultIfEmpty)private static java.lang.StringmanualTitle(CommandLine.Model.CommandSpec spec)private static booleanmkdirs(ManPageGenerator.Config config, java.io.File directory)private static voidoptionListGroups(java.util.List<CommandLine.Model.ArgGroupSpec> groups, java.util.List<CommandLine.Model.ArgGroupSpec> result)private static java.util.List<CommandLine.Model.ArgGroupSpec>optionListGroups(CommandLine.Model.CommandSpec commandSpec)Returns the list ofArgGroupSpecs with a non-nullheading.(package private) static java.lang.StringstripPrefix(java.lang.String prefixed)private static voidtraceAllSpecs(CommandLine.Model.CommandSpec[] specs, ManPageGenerator.Config config)private static java.lang.StringversionString(CommandLine.Model.CommandSpec spec)(package private) static voidwriteCustomizableManPageTemplate(java.io.PrintWriter pw, java.io.File includeDir, CommandLine.Model.CommandSpec spec)private static voidwriteEndOfOptions(java.io.PrintWriter pw, CommandLine.Help.IOptionRenderer optionRenderer, CommandLine.Help.IParamLabelRenderer paramLabelRenderer, CommandLine.Model.OptionSpec option)Write the end of options.private static voidwriteOption(java.io.PrintWriter pw, CommandLine.Help.IOptionRenderer optionRenderer, CommandLine.Help.IParamLabelRenderer paramLabelRenderer, CommandLine.Model.OptionSpec option)private static voidwritePositional(java.io.PrintWriter pw, CommandLine.Model.PositionalParamSpec positional, CommandLine.Help.IParameterRenderer parameterRenderer, CommandLine.Help.IParamLabelRenderer paramLabelRenderer)static voidwriteSingleManPage(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
-
-
-
Field Detail
-
EXIT_CODE_TEMPLATE_EXISTS
static final int EXIT_CODE_TEMPLATE_EXISTS
- See Also:
- Constant Field Values
-
BOLD
static final CommandLine.Help.Ansi.IStyle BOLD
-
ITALIC
static final CommandLine.Help.Ansi.IStyle ITALIC
-
HIGHLIGHT
static final CommandLine.Help.Ansi.IStyle HIGHLIGHT
-
COLOR_SCHEME
static final CommandLine.Help.ColorScheme COLOR_SCHEME
-
config
ManPageGenerator.Config config
-
spec
CommandLine.Model.CommandSpec spec
-
-
Method Detail
-
call
public java.lang.Integer call() throws java.io.IOExceptionInvokesgenerateManPage(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:
callin interfacejava.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.
-
createMarkupMap
private static java.util.Map<java.lang.String,CommandLine.Help.Ansi.IStyle> createMarkupMap()
-
main
public static void main(java.lang.String[] args)
InvokesgenerateManPage(Config, CommandLine.Model.CommandSpec...)to generate man pages for the user-specified@Command-annotated classes.If the
--exitoption is specified,System.exitis 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.IOExceptionGenerates AsciiDoc files for the specified classes to the specified output directory, optionally also generating template files in thecustomizablePagesDirectorydirectory.- 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 processingoverwriteCustomizablePages- 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
-
generateManPage
static int generateManPage(ManPageGenerator.Config config, CommandLine.Model.CommandSpec... specs) throws java.io.IOException
- Throws:
java.io.IOException
-
traceAllSpecs
private static void traceAllSpecs(CommandLine.Model.CommandSpec[] specs, ManPageGenerator.Config config)
-
generateSingleManPage
private static int generateSingleManPage(ManPageGenerator.Config config, CommandLine.Model.CommandSpec spec) throws java.io.IOException
- Throws:
java.io.IOException
-
mkdirs
private static boolean mkdirs(ManPageGenerator.Config config, java.io.File directory)
-
makeFileName
private static java.lang.String makeFileName(CommandLine.Model.CommandSpec spec)
-
generateSingleManPage
private static void generateSingleManPage(CommandLine.Model.CommandSpec spec, java.io.File manpage) throws java.io.IOException
- Throws:
java.io.IOException
-
generateCustomizableTemplate
private static int generateCustomizableTemplate(ManPageGenerator.Config config, CommandLine.Model.CommandSpec spec) throws java.io.IOException
- Throws:
java.io.IOException
-
writeCustomizableManPageTemplate
static void writeCustomizableManPageTemplate(java.io.PrintWriter pw, java.io.File includeDir, CommandLine.Model.CommandSpec spec)
-
writeSingleManPage
public static void writeSingleManPage(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
-
genHeader
static void genHeader(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
-
versionString
private static java.lang.String versionString(CommandLine.Model.CommandSpec spec)
-
manualTitle
private static java.lang.String manualTitle(CommandLine.Model.CommandSpec spec)
-
headerDescriptionString
private static java.lang.String headerDescriptionString(CommandLine.Model.CommandSpec spec)
-
genOptions
static void genOptions(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
-
optionListGroups
private static java.util.List<CommandLine.Model.ArgGroupSpec> optionListGroups(CommandLine.Model.CommandSpec commandSpec)
Returns the list ofArgGroupSpecs with a non-nullheading.
-
optionListGroups
private static void optionListGroups(java.util.List<CommandLine.Model.ArgGroupSpec> groups, java.util.List<CommandLine.Model.ArgGroupSpec> result)
-
writeOption
private static void writeOption(java.io.PrintWriter pw, CommandLine.Help.IOptionRenderer optionRenderer, CommandLine.Help.IParamLabelRenderer paramLabelRenderer, CommandLine.Model.OptionSpec option)
-
writePositional
private static void writePositional(java.io.PrintWriter pw, CommandLine.Model.PositionalParamSpec positional, CommandLine.Help.IParameterRenderer parameterRenderer, CommandLine.Help.IParamLabelRenderer paramLabelRenderer)
-
writeEndOfOptions
private static void writeEndOfOptions(java.io.PrintWriter pw, CommandLine.Help.IOptionRenderer optionRenderer, CommandLine.Help.IParamLabelRenderer paramLabelRenderer, CommandLine.Model.OptionSpec option)Write the end of options.
-
genPositionalArgs
static void genPositionalArgs(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
-
genCommands
static void genCommands(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
-
genExitStatus
static void genExitStatus(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
-
genFooter
static void genFooter(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
-
makeHeading
private static java.lang.String makeHeading(java.lang.String heading, java.lang.String defaultIfEmpty)
-
createOrderComparatorIfNecessary
private static java.util.Comparator<CommandLine.Model.OptionSpec> createOrderComparatorIfNecessary(java.util.List<CommandLine.Model.OptionSpec> options)
-
join
private static java.lang.String join(java.lang.String sep, java.lang.Object... lines)
-
firstElement
private static java.lang.String firstElement(java.lang.String[] elements)
-
empty
private static boolean empty(java.lang.Object[] array)
-
stripPrefix
static java.lang.String stripPrefix(java.lang.String prefixed)
-
-