Documentation
¶
Overview ¶
Package mff provides mango man-page support for ff/v4 applications.
High-level API ¶
For applications that use ff's ff.Command tree, NewManPage builds a fully-populated mango.ManPage in one call:
man, err := mff.NewManPage(1, rootCmd)
WriteManPage goes one step further and renders directly to an io.Writer:
if *manFlag {
if err := mff.WriteManPage(1, rootCmd, os.Stdout, roff.NewDocument()); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
os.Exit(0)
}
Flags are rendered with their type placeholder and default value when available, so `--port STRING (default: 8080)` appears instead of `--port`. ff suppresses trivial defaults (false for booleans, empty string) and placeholders (default-false bool flags only). A bool flag defined with BoolDefault/BoolLongDefault and a true default is not trivial: it renders with a BOOL placeholder and a "(default: true)" annotation so readers know the flag is active unless explicitly negated with --flag=false.
Low-level API ¶
FFlagVisitor and FFlagCommandVisitor mirror the visitor pattern from mango-pflag and are useful when working with a flat ff.FlagSet that is not part of a ff.Command tree:
if err := fs.WalkFlags(mff.FFlagVisitor(manPage)); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
PopulateManPage and AddCommand let callers control ManPage construction while still delegating the tree-walking to this package.
Index ¶
- func AddCommand(parent *mango.Command, cmd *ff.Command) error
- func FFlagCommandVisitor(c *mango.Command) func(ff.Flag) error
- func FFlagVisitor(m *mango.ManPage) func(ff.Flag) error
- func NewManPage(section uint, cmd *ff.Command) (*mango.ManPage, error)
- func PopulateManPage(m *mango.ManPage, cmd *ff.Command) error
- func WriteManPage(section uint, cmd *ff.Command, w io.Writer, b mango.Builder) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCommand ¶
AddCommand recursively adds an ff.Command and all its subcommands to a mango.Command parent. Each node is populated with its own flags only; flags inherited from parent sets are omitted.
func FFlagCommandVisitor ¶
FFlagCommandVisitor returns a function suitable for use with FlagSet.WalkFlags that adds each flag to a specific mango.Command.
if err := cmd.Flags.WalkFlags(mff.FFlagCommandVisitor(mangoCmd)); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
func FFlagVisitor ¶
FFlagVisitor returns a function suitable for use with FlagSet.WalkFlags that adds each flag to the root command of a mango.ManPage.
if err := fs.WalkFlags(mff.FFlagVisitor(manPage)); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
func NewManPage ¶
NewManPage builds a mango.ManPage from an ff.Command tree.
The one-line description is taken from cmd.ShortHelp; if that is empty, the first line of cmd.LongHelp is used as a fallback. cmd.LongHelp, when non-empty, becomes the long description.
Each subcommand is recursively added via AddCommand. Flags inherited from parent flag sets are omitted from subcommand sections, as they appear in the parent section.
func PopulateManPage ¶
PopulateManPage populates a mango.ManPage from an ff.Command tree. The root command's own flags are added to manPage.Root; each subcommand is recursively added via AddCommand.
Use NewManPage when the description should come directly from cmd.ShortHelp and cmd.LongHelp. Use PopulateManPage when you need a description that differs from the command's help text — construct the mango.ManPage yourself (calling mango.NewManPage with a custom description, then mango.ManPage.WithSection etc.) and then pass it here.
func WriteManPage ¶
WriteManPage generates a man page for cmd and writes it to w using b. It is a convenience wrapper around NewManPage and mango.ManPage.Build.
Typical use, after parsing flags:
if *manFlag {
if err := mff.WriteManPage(1, rootCmd, os.Stdout, roff.NewDocument()); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
os.Exit(0)
}
Types ¶
This section is empty.