docgen

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Native help, completion and reference generation

Go owns command descriptions in commands/*_description.go, beside each command family. A description defines prose, examples, semantic parameter names/types, choices, declaration order and presentation details once. docgen.Parameter shares that information between reference documentation, terminal help and shell completion. There is no embedded Python metadata snapshot or runtime Python.

The live Cobra registry remains authoritative for command/flag membership, aliases, arity, repeatability and defaults. commands.Description supplies the additional semantic details lazily for the requested command. commands.Documentation walks the full tree only when generating reference files. Keep descriptions and command implementations together when adding or changing a command.

The existing native formatters retain Python's help layout, wrapping, colors, links and section ordering. Bash/Zsh/Fish completion keeps the existing _AVR_COMPLETE protocol. Help/completion do not load credentials or call the API.

Native Go regression tests cover command help, styles, sanitization, completion and reference generation. make go-integration additionally exercises installed shell completion and bundled README discovery. Migration-only Python comparison tools were retired after validating the transition; their code and results remain in Git history at f5688c1. New behavior is tested against the native contract.

make go-docs renders Markdown, JSON, Starlight and man pages with the native binary and passes the README explicitly. A packaged binary looks for its optional README beside the executable. Documentation commands generate the public reference.

Documentation

Overview

Package docgen renders the public CLI reference in the existing documentation formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

func JSON(tree *Tree) (string, error)

func Man

func Man(tree *Tree) map[string]string

Man generates the root and every visible command's troff page.

func Markdown

func Markdown(tree *Tree) string

func Starlight

func Starlight(tree *Tree, readme *string) map[string]string

Starlight generates one page per visible top-level public command.

Types

type CompletionParam

type CompletionParam struct {
	Name     string         `json:"name"`
	Kind     string         `json:"kind"`
	Names    []string       `json:"names"`
	Help     string         `json:"help"`
	Multiple bool           `json:"multiple"`
	Flag     bool           `json:"flag"`
	Hidden   bool           `json:"hidden"`
	Nargs    int            `json:"nargs"`
	Type     CompletionType `json:"type"`
}

type CompletionType

type CompletionType struct {
	Kind          string   `json:"param_type"`
	Choices       []string `json:"choices"`
	CaseSensitive bool     `json:"case_sensitive"`
	FileOkay      bool     `json:"file_okay"`
}

type Describer

type Describer func(*cobra.Command) Description

type Description

type Description struct {
	Help, Short, CompletionHelp, Epilog string
	Usage                               []string
	Sections                            bool
	SectionOrder                        []string
	Parameters                          []Parameter
	Commands                            []HelpCommand
}

type HelpCommand

type HelpCommand struct {
	Name        string  `json:"name"`
	Description string  `json:"description"`
	Section     *string `json:"section"`
	AutoShort   bool    `json:"auto_short,omitempty"`
}

type HelpOption

type HelpOption struct {
	Names       []string `json:"names"`
	Label       string   `json:"label"`
	Description string   `json:"description"`
}

type HelpSpec

type HelpSpec struct {
	CompletionHelp   string            `json:"completion_help"`
	CompletionParams []CompletionParam `json:"completion_params"`
	Sections         bool              `json:"sections"`
	Help             string            `json:"help"`
	Epilog           string            `json:"epilog"`
	Usage            []string          `json:"usage"`
	Options          []HelpOption      `json:"options"`
	Commands         []HelpCommand     `json:"commands"`
	NoArgsIsHelp     bool              `json:"no_args_is_help"`
	SectionOrder     []string          `json:"section_order"`
}

func Help

func Help(c *cobra.Command, describe Describer) HelpSpec

Help derives all three terminal views from one Go-owned parameter description. Callers still filter against live flags, so composed removals/additions work.

type Node

type Node struct {
	Name        string   `json:"name"`
	Path        []string `json:"path"`
	Full        string   `json:"full"`
	IsGroup     bool     `json:"is_group"`
	ShortHelp   string   `json:"short_help"`
	Help        *string  `json:"help"`
	Epilog      *string  `json:"epilog"`
	Deprecated  any      `json:"deprecated"`
	Hidden      bool     `json:"hidden"`
	Usage       string   `json:"usage"`
	Params      []Param  `json:"params"`
	Subcommands []*Node  `json:"subcommands"`
}

type Param

type Param struct {
	Name        string   `json:"name"`
	Kind        string   `json:"kind"`
	Opts        []string `json:"opts"`
	Secondary   []string `json:"secondary_opts"`
	Type        string   `json:"type"`
	Required    bool     `json:"required"`
	Multiple    bool     `json:"multiple"`
	Nargs       int      `json:"nargs"`
	IsFlag      bool     `json:"is_flag"`
	Envvar      any      `json:"envvar"`
	Help        *string  `json:"help"`
	Hidden      bool     `json:"hidden"`
	ShowDefault bool     `json:"show_default"`
	Default     any      `json:"default"`
	Choices     []string `json:"choices,omitempty"`
}

type Parameter

type Parameter struct {
	Param
	Label, Suffix, DisplayHelp string
	CompletionKind             string
	CaseSensitive, FileOkay    bool
}

Parameter is shared by reference docs, terminal help and completion. Param holds semantic details absent from Cobra's string-valued flags.

type Section

type Section struct {
	Name     string
	Commands []string
}

type Tree

type Tree struct {
	Program       string             `json:"program"`
	Version       string             `json:"version"`
	Summary       string             `json:"summary"`
	GlobalOptions []Param            `json:"global_options"`
	Aliases       map[string]string  `json:"aliases"`
	SectionOrder  []string           `json:"section_order"`
	Sections      map[string][]*Node `json:"sections"`
}

func Build

func Build(root *cobra.Command, describe Describer, sections []Section) (*Tree, error)

Build derives reference output from the live Go command tree and descriptions.

Jump to

Keyboard shortcuts

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