cmdregistry

package
v1.67.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cmdregistry provides a self-registration mechanism for Cobra subcommands. New command packages call Register (typically from init()) so they appear in the root command without editing root.go.

The package exposes both an instance-based Registry (useful for testing) and a package-level global (used by production init() registrations).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(f *factory.Factory) []*cobra.Command

All returns all commands registered in the package-level global registry, sorted alphabetically by Use. Called once from root.go after the fixed AddCommand block.

func Register

func Register(b Builder)

Register adds a builder to the package-level global registry. Call this from init() in any command package.

Types

type Builder

type Builder func(*factory.Factory) *cobra.Command

Builder is a function that constructs a *cobra.Command given a factory.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds a set of command builders and can materialise them in deterministic order.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty Registry.

func (*Registry) All

func (r *Registry) All(f *factory.Factory) []*cobra.Command

All applies every registered builder to f and returns the resulting commands sorted alphabetically by Use. The sort is deterministic regardless of init() order, which varies across build systems and test binaries.

func (*Registry) Register

func (r *Registry) Register(b Builder)

Register appends a builder to the registry. Safe to call from init().

Jump to

Keyboard shortcuts

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