manpage

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package manpage provides a Nabat extension that installs a `man` subcommand generating roff documentation for the command tree. Install 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

View Source
var ErrNilOption = errors.New("nabat/manpage: option is nil")

ErrNilOption is returned when a nil Option is passed to New.

Functions

func New

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

New returns a nabat.Extension that installs the man subcommand. A nil opts entry returns ErrNilOption. It also fails on an empty WithCommandName or a section outside 1-9.

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