Documentation
¶
Index ¶
- Constants
- Variables
- type ArgDef
- type CommandNode
- type CommandTree
- type DynamicSetup
- type Example
- type FlagDef
- type HelpGenerator
- type HelpText
- type NodeMeta
- type ProgrammaticSetup
- type Registry
- func (r *Registry) AllFlagsForNode(node *CommandNode) []FlagDef
- func (r *Registry) ExecutableCommands() []*CommandNode
- func (r *Registry) GetByPath(path string) *CommandNode
- func (r *Registry) Resolve(args []string) (*CommandNode, []string)
- func (r *Registry) Root() *CommandNode
- func (r *Registry) Tree() *CommandTree
- func (r *Registry) Walk(fn func(node *CommandNode, depth int) bool)
- type RegistryManager
- type RegistrySetup
- type StaticSetup
- type ValidationError
- type ValidationResult
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 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 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 ProgrammaticSetup ¶
type ProgrammaticSetup struct {
Build func(context.Context) (*CommandTree, error)
}
func NewProgrammaticSetup ¶
func NewProgrammaticSetup(build func(context.Context) (*CommandTree, error)) *ProgrammaticSetup
func (*ProgrammaticSetup) Setup ¶
func (s *ProgrammaticSetup) Setup(ctx context.Context) (*CommandTree, error)
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) Root ¶
func (r *Registry) Root() *CommandNode
func (*Registry) Tree ¶
func (r *Registry) Tree() *CommandTree
type RegistryManager ¶
type RegistryManager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func NewManager(setup RegistrySetup) *RegistryManager
func (*RegistryManager) OnRebuild ¶
func (m *RegistryManager) OnRebuild(fn func(*Registry))
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 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
Click to show internal directories.
Click to hide internal directories.