registry

package
v1.0.15 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	FlagTypeString      = "string"
	FlagTypeInt         = "int"
	FlagTypeFloat       = "float"
	FlagTypeBool        = "bool"
	FlagTypeStringSlice = "string-slice"
	FlagTypeStringArray = "string-array"
	FlagTypeIntSlice    = "int-slice"
	FlagTypeObject      = "object"
	FlagTypeObjectSlice = "object-slice"
)

Variables

View Source
var BuiltinFlags = []FlagDef{
	{Name: "set", Type: FlagTypeStringSlice, Description: "Set nested parameters using key=value, supports dot path."},
	{Name: "params", Short: "P", Type: FlagTypeString, Description: "JSON object whose top-level keys are merged as CLI flags."},
	{Name: "dry-run", Type: FlagTypeBool, Description: "Render the normalized request without executing the backend."},
	{Name: "format", Short: "o", Type: FlagTypeString, Enum: []string{"json", "ndjson", "table"}, Description: "Output format. Default json."},
	{Name: "select", Type: FlagTypeString, Description: "Field projection; comma-separated dot paths, e.g. id,creator.email."},
	{Name: "envelope", Type: FlagTypeBool, Description: "Wrap result in {data, meta, error} envelope."},
	{Name: "verbose", Short: "v", Type: FlagTypeBool, Description: "Show more columns in --format table."},
	{Name: "auto-paginate", Type: FlagTypeBool, Description: "Automatically fetch and merge all pages when the response contains pagination signals (next_page_token or pagination.has_more)."},
}

Functions

This section is empty.

Types

type ArgDef

type ArgDef struct {
	Name        string
	Required    bool
	Variadic    bool
	Description string
}

type CommandNode

type CommandNode struct {
	Name       string
	Aliases    []string
	Help       HelpText
	Flags      []FlagDef
	Args       []ArgDef
	Children   []*CommandNode
	HandlerRef string
	Meta       NodeMeta
	// contains filtered or unexported fields
}

func (*CommandNode) FullPath

func (n *CommandNode) FullPath() []string

func (*CommandNode) FullPathString

func (n *CommandNode) FullPathString() string

func (*CommandNode) InheritedFlags

func (n *CommandNode) InheritedFlags() []FlagDef

func (*CommandNode) IsExecutable

func (n *CommandNode) IsExecutable() bool

func (*CommandNode) IsGroup

func (n *CommandNode) IsGroup() bool

func (*CommandNode) VisibleChildren

func (n *CommandNode) VisibleChildren() []*CommandNode

type CommandTree

type CommandTree struct {
	Version     string
	GlobalFlags []FlagDef
	Nodes       []*CommandNode
}

type DynamicSetup

type DynamicSetup interface {
	RegistrySetup
	OnChange(ctx context.Context, notify func()) error
}

type Example

type Example struct {
	Description string
	Command     string
}

type FlagDef

type FlagDef struct {
	Name        string
	Short       string
	Type        string
	Required    bool
	Default     any
	Enum        []string
	Hidden      bool
	Description string
	Deprecated  string
}

type HelpGenerator

type HelpGenerator struct{}

func (*HelpGenerator) Render

func (g *HelpGenerator) Render(node *CommandNode) string

Render produces a complete help text for any node regardless of depth. The output follows the canonical layout:

<brief>
<blank line>
<long description>
<blank line>
Usage:
  <path> [command|flags] [args]
<blank line>
Available Commands:   (if group)
  <name>  <brief>
<blank line>
Args:                 (if leaf with positional args)
  <name>  <description>
<blank line>
Flags:
  --<name>   <description>
<blank line>
Examples:             (if any)
  # <description>
  <command>
<blank line>
Use "<path> [command] --help" for more information about a command.

type HelpText

type HelpText struct {
	Brief        string
	Long         string
	TemplateVars map[string]string
	Examples     []Example
}

type NodeMeta

type NodeMeta struct {
	Hidden     bool
	Dangerous  bool
	Deprecated string
	Scope      string
	Tags       map[string]string
}

type ProgrammaticSetup

type ProgrammaticSetup struct {
	Build func(context.Context) (*CommandTree, error)
}

func NewProgrammaticSetup

func NewProgrammaticSetup(build func(context.Context) (*CommandTree, error)) *ProgrammaticSetup

func (*ProgrammaticSetup) Setup

type Registry

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

func New

func New(tree *CommandTree) (*Registry, error)

func (*Registry) AllFlagsForNode

func (r *Registry) AllFlagsForNode(node *CommandNode) []FlagDef

func (*Registry) ExecutableCommands

func (r *Registry) ExecutableCommands() []*CommandNode

func (*Registry) GetByPath

func (r *Registry) GetByPath(path string) *CommandNode

func (*Registry) Resolve

func (r *Registry) Resolve(args []string) (*CommandNode, []string)

func (*Registry) Root

func (r *Registry) Root() *CommandNode

func (*Registry) Tree

func (r *Registry) Tree() *CommandTree

func (*Registry) Walk

func (r *Registry) Walk(fn func(node *CommandNode, depth int) bool)

type RegistryManager

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

func NewManager

func NewManager(setup RegistrySetup) *RegistryManager

func (*RegistryManager) Init

func (m *RegistryManager) Init(ctx context.Context) error

func (*RegistryManager) OnRebuild

func (m *RegistryManager) OnRebuild(fn func(*Registry))

func (*RegistryManager) Rebuild

func (m *RegistryManager) Rebuild(ctx context.Context) error

func (*RegistryManager) Registry

func (m *RegistryManager) Registry() *Registry

type RegistrySetup

type RegistrySetup interface {
	Setup(ctx context.Context) (*CommandTree, error)
}

type StaticSetup

type StaticSetup struct {
	Tree *CommandTree
}

func NewStaticSetup

func NewStaticSetup(tree *CommandTree) *StaticSetup

func (*StaticSetup) Setup

func (s *StaticSetup) Setup(ctx context.Context) (*CommandTree, error)

type ValidationError

type ValidationError struct {
	Path    string
	Field   string
	Rule    string
	Level   string
	Message string
}

type ValidationResult

type ValidationResult struct {
	Errors   []ValidationError
	Warnings []ValidationError
}

func ValidateTree

func ValidateTree(tree *CommandTree) *ValidationResult

ValidateTree runs all validation rules (R1–R14) against a CommandTree. Rules R1-R10, R13 produce errors; R11, R12, R14 produce warnings.

func (*ValidationResult) Error

func (r *ValidationResult) Error() string

func (*ValidationResult) HasErrors

func (r *ValidationResult) HasErrors() bool

Jump to

Keyboard shortcuts

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