Documentation
¶
Index ¶
- func DefaultFlagTypeMatcher(expr ast.Expr) bool
- func LongDescriptionFunc(descs map[string]*LongDescription, fb LongDescriptionFallback) func(*PluginArg) *LongDescription
- func LongDescriptionMarkdown(d *LongDescription) string
- func LongDescriptionYAMLBlock(d *LongDescription, indent string) string
- func LongDescriptions(sourcePath string, matchers ...FlagTypeMatcher) (map[string]*LongDescription, error)
- func LongDescriptionsFor(sourcePath string, matchers ...FlagTypeMatcher) map[string]*LongDescription
- func ToMarkdown(app *cli.Command) (string, error)
- func ToMarkdownWithSource(app *cli.Command, sourcePath string) (string, error)
- type CliTemplate
- type FlagTypeMatcher
- type LongDescription
- type LongDescriptionFallback
- type PluginArg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultFlagTypeMatcher ¶
DefaultFlagTypeMatcher matches the urfave/cli/v3 core flag composite literals: BoolFlag, StringFlag, IntFlag and StringSliceFlag. Custom flag types are intentionally not matched here — see LongDescriptions for the extension mechanism.
func LongDescriptionFunc ¶
func LongDescriptionFunc( descs map[string]*LongDescription, fb LongDescriptionFallback, ) func(*PluginArg) *LongDescription
LongDescriptionFunc returns a template function that resolves a PluginArg's long description by first consulting descs and then invoking fb when no extracted description is available. Pass nil for fb to disable the fallback and have missing entries return nil directly.
Typical usage from a renderer:
funcs["longDesc"] = docs.LongDescriptionFunc(descs, docs.ShortDescriptionFallback)
Or, when no fallback is wanted:
funcs["longDesc"] = docs.LongDescriptionFunc(descs, nil)
func LongDescriptionMarkdown ¶
func LongDescriptionMarkdown(d *LongDescription) string
LongDescriptionMarkdown renders a structured LongDescription as a markdown-ready string. Line breaks inside a paragraph collapse to a single space so markdown renderers flow the text as one sentence; each paragraph is prefixed with " " to visually align with the short Description line that precedes it.
func LongDescriptionYAMLBlock ¶
func LongDescriptionYAMLBlock(d *LongDescription, indent string) string
LongDescriptionYAMLBlock renders a structured LongDescription as the body of a YAML literal block scalar. Every source line is prefixed with indent; paragraphs are separated by a blank line so the visual structure of the original comment is preserved end-to-end; the separator blank lines carry no trailing whitespace.
The function is the format-agnostic building block — it knows about YAML's `|` literal-block rules but not about any specific data schema. Consumers compose the surrounding "key: |" line themselves (the key name and nesting depth vary per consumer and determine the required indent).
func LongDescriptions ¶
func LongDescriptions(sourcePath string, matchers ...FlagTypeMatcher) (map[string]*LongDescription, error)
LongDescriptions parses sourcePath and extracts a LongDescription for every flag composite literal whose type matches at least one of the supplied matchers (OR semantics; evaluation short-circuits at the first match). When matchers is empty, only DefaultFlagTypeMatcher is applied.
A // comment block directly above an &<flag>Flag{...} literal is treated as the long docs description; a blank line in the source between the comment and the literal breaks the association.
A typical call site that wants both urfave core flags and wp-plugin-go custom flag types:
docs.LongDescriptions(
"plugin/plugin.go",
docs.DefaultFlagTypeMatcher,
docs.SelectorMatcher("plugin_cli", "StringMapFlag", "DeepStringMapFlag"),
)
func LongDescriptionsFor ¶
func LongDescriptionsFor(sourcePath string, matchers ...FlagTypeMatcher) map[string]*LongDescription
LongDescriptionsFor is the template-data convenience wrapper around LongDescriptions. It normalises flag names so "upload.metadata" matches the env-derived "upload_metadata", and returns an empty map (instead of an error) when sourcePath is empty or unparseable, so a missing source never breaks a docs pipeline.
func ToMarkdown ¶
ToMarkdown creates a markdown string for the `*App` without long descriptions. It is a convenience wrapper around ToMarkdownWithSource that passes an empty sourcePath.
func ToMarkdownWithSource ¶
ToMarkdownWithSource creates a markdown string for the `*App`. If sourcePath points to a readable Go source file, long descriptions are extracted from leading doc comments above each flag's composite literal and merged into the rendered output. An empty sourcePath disables long description lookup. The function errors if either parsing or writing of the string fails.
Types ¶
type CliTemplate ¶
type CliTemplate struct {
Name string
Version string
Description string
Usage string
UsageText string
GlobalArgs []*PluginArg
}
CliTemplate is the template-data root handed to the markdown template by GetTemplateDataWithSource.
func GetTemplateData ¶
func GetTemplateData(app *cli.Command) *CliTemplate
GetTemplateData returns the template data for the `*App` without long descriptions. It is a convenience wrapper around GetTemplateDataWithSource that passes an empty sourcePath.
func GetTemplateDataWithSource ¶
func GetTemplateDataWithSource(app *cli.Command, sourcePath string) *CliTemplate
GetTemplateDataWithSource returns the template data for the `*App`. If sourcePath points to a readable Go source file, long descriptions are extracted from leading doc comments above each flag's composite literal and merged into the returned data. An empty sourcePath disables long description lookup.
type FlagTypeMatcher ¶
FlagTypeMatcher reports whether an AST type expression refers to a flag composite literal that the caller wants documented. See DefaultFlagTypeMatcher for the built-in matcher and LongDescriptions for usage.
func SelectorMatcher ¶
func SelectorMatcher(pkg string, names ...string) FlagTypeMatcher
SelectorMatcher returns a FlagTypeMatcher that matches selector expressions whose package ident equals pkg and whose selector name is in names. Use it to build a matcher for custom flag types:
docs.SelectorMatcher("plugin_cli", "StringMapFlag", "DeepStringMapFlag")
type LongDescription ¶
type LongDescription struct {
// Paragraphs indexes paragraphs (outer) × source lines (inner).
Paragraphs [][]string
}
LongDescription is a structured representation of the leading doc comment above a flag literal. Source layout is preserved so consumers can adapt it to any output format (markdown, YAML literal blocks, AsciiDoc, etc.) without re-parsing a flattened string.
Paragraphs split on empty // lines — the standard godoc/JSDoc convention. Each Paragraph keeps its original source lines (the "// " comment prefix is stripped, but additional leading whitespace such as the two-space indent used for markdown list-item continuations is preserved verbatim).
func ShortDescriptionFallback ¶
func ShortDescriptionFallback(arg *PluginArg) *LongDescription
ShortDescriptionFallback returns a LongDescription synthesised from arg.Description as a single sentence-formatted paragraph. It is the canonical fallback for renderers whose schema exposes only a single description channel (e.g. a YAML "description:" block) and need to keep flags defined in the plugin library visible in the output. Returns nil when Description is empty.
func (*LongDescription) Flat ¶
func (d *LongDescription) Flat() string
Flat returns the description as a single string — the canonical lossless serialisation. Lines inside a paragraph are joined with "\n" and paragraphs are joined with "\n\n".
func (*LongDescription) IsZero ¶
func (d *LongDescription) IsZero() bool
IsZero reports whether the receiver has no paragraphs.
func (*LongDescription) String ¶
func (d *LongDescription) String() string
String implements fmt.Stringer and is equivalent to Flat.
type LongDescriptionFallback ¶
type LongDescriptionFallback func(*PluginArg) *LongDescription
LongDescriptionFallback derives a LongDescription from a PluginArg when no extracted long description is available. Implementations should return nil when no usable description can be derived so callers can distinguish "render this fallback" from "nothing to render".
type PluginArg ¶
type PluginArg struct {
Name string
EnvVars []string
Description string
LongDescription string
Default string
Type string
Required bool
}
PluginArg is one flag in the rendered CLI doc, populated by parseFlags. LongDescription is the markdown-formatted string produced by LongDescriptionMarkdown — it is *not* the structured *LongDescription type, despite sharing a name.