manpage

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

func New(opts ...Option) (nabat.Extension, error)

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

func WithCommandName(name string) Option

WithCommandName overrides the man subcommand name (default "man").

func WithHidden

func WithHidden() Option

WithHidden hides the man subcommand from help listings.

func WithSection

func WithSection(n int) Option

WithSection sets the default man page section (1-9; default 1). Users can override at runtime via --section.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL