Documentation
¶
Overview ¶
Package manpage provides a Nabat extension that installs a `man` subcommand generating roff/man-page documentation for the entire command tree. Install it with nabat.WithExtension.
import (
"nabat.dev/nabat"
"nabat.dev/manpage"
)
app := nabat.MustNew("myctl", nabat.WithExtension(manpage.New(manpage.WithSection(8))))
Defaults: subcommand "man", section 1, hidden=false.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New builds a nabat.Extension that installs the man subcommand and returns an error when any option is nil, when option application fails, or when the configuration is invalid.
Errors:
- "nabat/manpage: option at index N is nil": an entry in opts is nil.
- errors wrapped with "nabat/manpage: option at index N": Option application failed.
- "nabat/manpage: command name cannot be empty": WithCommandName set an empty name.
- "nabat/manpage: section must be between 1 and 9, got N": the effective section is out of range.
Example ¶
package main
import (
"context"
"fmt"
"strings"
"nabat.dev/manpage"
"nabat.dev/nabat"
"nabat.dev/nabat/nabattest"
)
func main() {
io, _, stdout, _ := nabattest.NewIO()
app := nabat.MustNew("myctl",
nabat.WithIO(io),
nabat.WithExtension(manpage.New()),
)
if err := app.RunArgs(context.Background(), "man"); err != nil {
fmt.Println("error:", err)
return
}
doc := strings.TrimSpace(stdout.String())
if strings.HasPrefix(doc, ".TH") {
fmt.Println("roff")
} else {
fmt.Println("unexpected format")
}
}
Output: roff
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures the manpage extension.
func WithCommandName ¶
WithCommandName overrides the man subcommand name (default "man").
func WithSection ¶
WithSection sets the default man page section (1-9; default 1). Users can override at runtime via --section.
Click to show internal directories.
Click to hide internal directories.