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 class
ManPageGenerator.App
(package private) static class
ManPageGenerator.Config
(package private) static class
ManPageGenerator.ShortestFirst
Sorts short strings before longer strings.(package private) static class
ManPageGenerator.SortByOrder<T extends CommandLine.Model.IOrdered>
(package private) static class
ManPageGenerator.SortByShortestOptionNameAlphabetically
SortsOptionSpec
instances by their name in case-insensitive alphabetic order.
-
Field Summary
Fields Modifier and Type Field Description (package private) static CommandLine.Help.Ansi.IStyle
BOLD
(package private) static CommandLine.Help.ColorScheme
COLOR_SCHEME
(package private) ManPageGenerator.Config
config
(package private) static int
EXIT_CODE_TEMPLATE_EXISTS
(package private) static CommandLine.Help.Ansi.IStyle
HIGHLIGHT
(package private) static CommandLine.Help.Ansi.IStyle
ITALIC
(package private) CommandLine.Model.CommandSpec
spec
-
Constructor Summary
Constructors Constructor Description ManPageGenerator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Integer
call()
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 boolean
empty(java.lang.Object[] array)
private static java.lang.String
firstElement(java.lang.String[] elements)
(package private) static void
genCommands(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
private static int
generateCustomizableTemplate(ManPageGenerator.Config config, CommandLine.Model.CommandSpec spec)
static int
generateManPage(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 thecustomizablePagesDirectory
directory.(package private) static int
generateManPage(ManPageGenerator.Config config, CommandLine.Model.CommandSpec... specs)
private static int
generateSingleManPage(ManPageGenerator.Config config, CommandLine.Model.CommandSpec spec)
private static void
generateSingleManPage(CommandLine.Model.CommandSpec spec, java.io.File manpage)
(package private) static void
genExitStatus(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
(package private) static void
genFooter(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
(package private) static void
genHeader(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
(package private) static void
genOptions(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
(package private) static void
genPositionalArgs(java.io.PrintWriter pw, CommandLine.Model.CommandSpec spec)
private static java.lang.String
headerDescriptionString(CommandLine.Model.CommandSpec spec)
private static java.lang.String
join(java.lang.String sep, java.lang.Object... lines)
static void
main(java.lang.String[] args)
InvokesgenerateManPage(Config, CommandLine.Model.CommandSpec...)
to generate man pages for the user-specified@Command
-annotated classes.private static java.lang.String
makeFileName(CommandLine.Model.CommandSpec spec)
private static java.lang.String
makeHeading(java.lang.String heading, java.lang.String defaultIfEmpty)
private static java.lang.String
manualTitle(CommandLine.Model.CommandSpec spec)
private static boolean
mkdirs(ManPageGenerator.Config config, java.io.File directory)
private static void
optionListGroups(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 ofArgGroupSpec
s with a non-null
heading.(package private) static java.lang.String
stripPrefix(java.lang.String prefixed)
private static void
traceAllSpecs(CommandLine.Model.CommandSpec[] specs, ManPageGenerator.Config config)
private static java.lang.String
versionString(CommandLine.Model.CommandSpec spec)
(package private) static void
writeCustomizableManPageTemplate(java.io.PrintWriter pw, java.io.File includeDir, CommandLine.Model.CommandSpec spec)
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.private static void
writeOption(java.io.PrintWriter pw, CommandLine.Help.IOptionRenderer optionRenderer, CommandLine.Help.IParamLabelRenderer paramLabelRenderer, CommandLine.Model.OptionSpec option)
private static void
writePositional(java.io.PrintWriter pw, CommandLine.Model.PositionalParamSpec positional, CommandLine.Help.IParameterRenderer parameterRenderer, CommandLine.Help.IParamLabelRenderer paramLabelRenderer)
static void
writeSingleManPage(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.IOException
InvokesgenerateManPage(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 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
--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 thecustomizablePagesDirectory
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 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 ofArgGroupSpec
s with a non-null
heading.
-
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)
-
-