Documentation
¶
Overview ¶
Package heraldhelp renders CLI help/usage output using herald typography.
It provides a Command model that captures the full structure of a CLI command (flags, arguments, subcommands, examples) and renders it with herald's styled typography methods.
Quick start (manual):
ty := herald.New()
cmd := heraldhelp.Command{
Name: "myapp",
Synopsis: "myapp [flags] <subcommand>",
}
fmt.Println(heraldhelp.Render(ty, cmd))
With the flag adapter:
cmd := heraldhelp.FromFlagSet("myapp", flag.CommandLine)
fmt.Println(heraldhelp.Render(herald.New(), cmd))
Index ¶
- Variables
- func FormatVersion(name, version string) string
- func Render(ty *herald.Typography, cmd Command, opts ...RenderOption) string
- func RenderTo(w io.Writer, ty *herald.Typography, cmd Command, opts ...RenderOption) error
- type Arg
- type Command
- type CommandGroup
- type CommandRef
- type Example
- type Flag
- type FlagGroup
- type RenderConfig
- type RenderOption
- type Section
- type Style
Constants ¶
This section is empty.
Variables ¶
var DefaultSectionOrder = []Section{ SectionName, SectionDeprecated, SectionSynopsis, SectionDescription, SectionArgs, SectionFlags, SectionInheritedFlags, SectionCommands, SectionExamples, SectionSeeAlso, SectionFooter, }
DefaultSectionOrder defines the default ordering of help sections.
Functions ¶
func FormatVersion ¶
FormatVersion returns a formatted version string suitable for the Footer field.
func Render ¶
func Render(ty *herald.Typography, cmd Command, opts ...RenderOption) string
Render renders the help output for a Command using the given Typography instance and returns it as a string. If ty is nil, an empty string is returned.
func RenderTo ¶
func RenderTo(w io.Writer, ty *herald.Typography, cmd Command, opts ...RenderOption) error
RenderTo renders the help output and writes it to w.
Types ¶
type Command ¶
type Command struct {
Name string // command name, e.g. "myapp"
Synopsis string // one-line usage, e.g. "myapp [flags] <subcommand>"
Description string // long description (may be multi-paragraph)
Aliases []string
Deprecated string // if non-empty, command is deprecated
Flags []Flag
FlagGroups []FlagGroup // cobra flag groups, kong groups, urfave categories
Args []Arg // positional arguments
Commands []CommandRef // subcommands (summary only, not recursive)
CommandGroups []CommandGroup // grouped subcommands
Examples []Example
SeeAlso []string
}
Command describes a CLI command for help rendering. It captures all the information typically shown in a --help page: name, synopsis, flags, subcommands, examples, etc.
type CommandGroup ¶
type CommandGroup struct {
Name string
Commands []CommandRef
}
CommandGroup groups related subcommands under a heading.
type CommandRef ¶
CommandRef is a summary reference to a subcommand. It does not recurse into the subcommand's own flags or children.
type Flag ¶
type Flag struct {
Long string // e.g. "--output"
Short string // e.g. "-o" (empty if none)
Type string // e.g. "string", "bool"
Default string // default value
Desc string // description
Required bool // whether the flag is required
Hidden bool // adapters skip hidden flags by default
EnvVars []string // environment variable bindings
Enum []string // enum values (kong)
Deprecated string // deprecation notice
Inherited bool // inherited/persistent flag (rendered in separate section)
}
Flag describes a single CLI flag.
type RenderConfig ¶
type RenderConfig struct {
Style Style // visual style (StyleRich or StyleCompact)
Width int // explicit terminal width override (0 = auto-detect)
SectionOrder []Section // section rendering order (nil = DefaultSectionOrder)
ShowHidden bool // include hidden flags in output
EnvVarDisplay bool // show environment variable bindings inline
}
RenderConfig holds configuration for help rendering. Use RenderOption functional options to customise the defaults.
type RenderOption ¶
type RenderOption func(*RenderConfig)
RenderOption is a functional option for Render/RenderTo.
func WithEnvVarDisplay ¶
func WithEnvVarDisplay(show bool) RenderOption
WithEnvVarDisplay enables inline display of environment variable bindings in flag descriptions (e.g. "Port number [$PORT]").
func WithSectionOrder ¶
func WithSectionOrder(order ...Section) RenderOption
WithSectionOrder sets the order of help sections. Sections not listed are omitted from the output.
func WithShowHidden ¶
func WithShowHidden(show bool) RenderOption
WithShowHidden includes hidden flags in the help output.
func WithStyle ¶
func WithStyle(s Style) RenderOption
WithStyle sets the visual style for help rendering. The default is StyleRich (decorated headings, bordered tables). Use StyleCompact for a minimal, terminal-native layout with colored text and indented columns.
func WithWidth ¶
func WithWidth(w int) RenderOption
WithWidth sets an explicit terminal width, overriding auto-detection.
type Section ¶
type Section int
Section identifies a renderable section of the help output.
const ( // SectionName renders the command name as H1. SectionName Section = iota // SectionDeprecated renders a deprecation warning alert. SectionDeprecated // SectionSynopsis renders the usage synopsis as a code block. SectionSynopsis // SectionDescription renders the long description as a paragraph. SectionDescription // SectionArgs renders positional arguments as a table. SectionArgs // SectionFlags renders flags (flat or grouped) as tables. SectionFlags // SectionInheritedFlags renders inherited/persistent flags as a table. SectionInheritedFlags // SectionCommands renders subcommands (flat or grouped) as tables. SectionCommands // SectionExamples renders usage examples with descriptions and code blocks. SectionExamples // SectionSeeAlso renders related commands/resources as a list. SectionSeeAlso SectionFooter )
type Style ¶
type Style int
Style controls the visual style of the rendered help output.
const ( // StyleCompact renders a minimal, terminal-native layout: uppercase // colored section headings, indented two-column lists for flags and // commands, and no table borders. Closer to traditional CLI help output // but with themed colors applied. This is the default style. StyleCompact Style = iota // StyleRich uses herald's full typography: bordered tables, decorated // headings (H1/H2/H3), code blocks, and alert panels. StyleRich // StyleGrouped wraps each section in a herald Fieldset with the section // name as the legend. Content inside uses compact-style KV layout. StyleGrouped // StyleMarkdown renders help as valid Markdown text. The output can be // piped to tools like glow or bat, saved to a file, or rendered back // through herald-md for themed terminal output. StyleMarkdown )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
compact/000_manual
command
A real CLI with a "greet" command and compact-style themed help via herald.
|
A real CLI with a "greet" command and compact-style themed help via herald. |
|
compact/001_flag
command
A real CLI using stdlib flag with compact-style themed help via herald.
|
A real CLI using stdlib flag with compact-style themed help via herald. |
|
compact/005_custom-theme
command
Themed help using a built-in herald theme (Dracula).
|
Themed help using a built-in herald theme (Dracula). |
|
demos
Package demos provides a shared Command for demo screenshots.
|
Package demos provides a shared Command for demo screenshots. |
|
demos/compact
command
StyleCompact demo for screenshot capture.
|
StyleCompact demo for screenshot capture. |
|
demos/grouped
command
StyleGrouped demo for screenshot capture.
|
StyleGrouped demo for screenshot capture. |
|
demos/markdown
command
StyleMarkdown demo for screenshot capture.
|
StyleMarkdown demo for screenshot capture. |
|
demos/rich
command
StyleRich demo for screenshot capture.
|
StyleRich demo for screenshot capture. |
|
grouped/000_manual
command
Render help with each section in a bordered fieldset.
|
Render help with each section in a bordered fieldset. |
|
markdown/000_manual
command
Render help as valid Markdown text.
|
Render help as valid Markdown text. |
|
rich/000_manual
command
A real CLI with a "greet" command and themed help via herald.
|
A real CLI with a "greet" command and themed help via herald. |
|
rich/001_flag
command
A real CLI using stdlib flag with themed help via herald.
|
A real CLI using stdlib flag with themed help via herald. |
|
urfave
module
|



