commandcatalog

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package commandcatalog turns an assembled cobra command tree into a structured, group-ordered catalog and renders it for two surfaces: a terminal cheat-sheet (used by `vaultmind help`) and a markdown reference (used by `vaultmind docs commands` and embedded into onboarding).

It is a pure transform — one generator, multiple consumers (SSOT). The catalog's group order, titles, and the "when"-annotation key are supplied by the caller (cmd/zz_catalog.go owns those constants), so this package carries no knowledge of VaultMind's specific groups and stays trivially testable against a fixture cobra tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderMarkdown

func RenderMarkdown(cat Catalog) string

RenderMarkdown renders the catalog as a stable markdown reference: an H1 title, then an H2 + table per group with Command / What / When columns. The output is deterministic (groups in declared order, commands path-sorted) so it can back a regenerate-and-diff drift gate.

func RenderTerminal

func RenderTerminal(cat Catalog) string

RenderTerminal renders the catalog as a grouped cheat-sheet for `help`: a title line per group, then one block per command — its path, its Short, and an indented "when you ..." trigger line.

Types

type Catalog

type Catalog struct {
	Groups []CatalogGroup
}

Catalog is the full structured result: groups in declared order, each with its path-sorted commands. Groups with no commands are omitted.

func Build

func Build(root *cobra.Command, opts Options) Catalog

Build walks the assembled command tree and returns a Catalog: every non-hidden command that carries a registered GroupID is bucketed into its group. Hidden commands and commands with no (or an unregistered) GroupID are excluded. Groups render in opts.Groups order; commands within a group are path-sorted. Empty groups are dropped.

type CatalogGroup

type CatalogGroup struct {
	ID       string
	Title    string
	Commands []Command
}

CatalogGroup is a rendered group: its title plus its member commands, path-sorted for deterministic output.

type Command

type Command struct {
	Path  string
	Short string
	When  string
}

Command is one cataloged command: its full invocation path, the Short (the WHAT line) and the when-to-use trigger (the WHEN line).

type Group

type Group struct {
	ID    string
	Title string
}

Group is one catalog section: a stable ID and its display title.

type Options

type Options struct {
	// Groups lists the catalog groups in the order they should render.
	Groups []Group
	// WhenKey is the Annotations key carrying the when-to-use trigger phrase.
	WhenKey string
}

Options configures Build: the groups in display order and the cobra Annotations key under which each command's when-to-use trigger is stored.

Jump to

Keyboard shortcuts

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