introspect

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package introspect walks a live cobra command tree and renders it as data. It is what backs `truestamp schema get commands`.

It reads the tree rather than a hand-maintained list on purpose: a description that is generated from the thing it describes cannot drift from it. That property is why the generated document can replace the golden help-text fixture as the reviewable artifact for a tree change — the diff of the schema *is* the design review.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LookupEnum

func LookupEnum(enums EnumValues, path, flag string) []string

lookupEnum prefers a command-scoped entry over a global one, so a flag whose valid values differ between two commands can say so. LookupEnum resolves a flag's closed value set: the path-scoped key first, then the bare flag name. Exported so shell completion and `schema get commands` resolve a flag the same way.

func Paths

func Paths(c Command) []string

Paths returns every command path in the tree, depth first. Used to assert the round-trip property: everything listed is invocable, and everything invocable is listed.

Types

type Command

type Command struct {
	Path        string    `json:"path"`
	Use         string    `json:"use"`
	Short       string    `json:"short"`
	Long        string    `json:"long,omitempty"`
	Example     string    `json:"example,omitempty"`
	Group       bool      `json:"group"`
	Runnable    bool      `json:"runnable"`
	Hidden      bool      `json:"hidden,omitempty"`
	Deprecated  string    `json:"deprecated,omitempty"`
	Aliases     []string  `json:"aliases,omitempty"`
	Flags       []Flag    `json:"flags,omitempty"`
	Subcommands []Command `json:"subcommands,omitempty"`
}

Command describes one node of the tree.

func Find

func Find(c Command, path string) (Command, bool)

Find returns the node at the given space-separated path, or false.

func Walk

func Walk(root *cobra.Command, enums EnumValues, includeHidden bool) Command

Walk renders root and everything under it. Hidden commands are included only when includeHidden is set: they are part of the tree, but they are not part of the interface, and `schema get commands` describes the interface by default.

type EnumValues

type EnumValues map[string][]string

EnumValues supplies the closed value set for a flag, keyed by "<command path>|<flag name>" or by "<flag name>" for a flag whose values are the same wherever it appears. Cobra does not model closed enums, so this is the one piece of information the tree cannot supply about itself; it is registered by the CLI and passed in.

type Flag

type Flag struct {
	Name      string   `json:"name"`
	Shorthand string   `json:"shorthand,omitempty"`
	Usage     string   `json:"usage"`
	Type      string   `json:"type"`
	Default   string   `json:"default,omitempty"`
	Values    []string `json:"values,omitempty"`
	Inherited bool     `json:"inherited"`
	Hidden    bool     `json:"hidden,omitempty"`
	// NoOptDefVal records that the flag may be passed without a value,
	// and what it means when it is. The CLI uses this for the interactive
	// sentinels (`--file` with no path opens a picker), which is exactly
	// the kind of thing an agent must not trip over.
	NoOptDefVal string `json:"no_opt_default,omitempty"`
}

Flag describes one flag as an agent needs to see it: enough to construct a valid invocation without reading prose.

Jump to

Keyboard shortcuts

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