parser

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseStruct added in v2.0.4

func ParseStruct(node *CommandNode, val reflect.Value) error

ParseStruct recursively parses the struct fields to build the command tree.

Example:

node := parser.NewCommandNode("init", "Initialize project", reflect.ValueOf(&InitCmd{}))
val := reflect.ValueOf(&InitCmd{})
err := parser.ParseStruct(node, val)

Types

type ArgMetadata

type ArgMetadata struct {
	Description string
	Required    bool
	IsGreedy    bool
	Field       reflect.Value
}

ArgMetadata holds information about a positional argument.

type CommandNode

type CommandNode struct {
	Name        string
	Description string
	Aliases     []string
	Flags       map[string]*FlagMetadata
	ShortFlags  map[string]string // Maps short name to full name
	Args        []*ArgMetadata
	Children    map[string]*CommandNode
	Value       reflect.Value
	Type        reflect.Type
}

CommandNode represents a node in the command tree.

func NewCommandNode

func NewCommandNode(name, description string, val reflect.Value) *CommandNode

NewCommandNode creates a new CommandNode with initialized maps.

Example:

node := parser.NewCommandNode("init", "Initialize project", reflect.ValueOf(&InitCmd{}))

func Parse

func Parse(name string, root any) (*CommandNode, error)

Parse parses a struct and returns a CommandNode tree.

Example:

root := &RootCmd{}
node, err := parser.Parse("apx", root)

type FlagMetadata

type FlagMetadata struct {
	Name        string
	Short       string
	Description string
	Default     string
	Env         string
	Required    bool
	Field       reflect.Value
}

FlagMetadata holds information about a flag.

Jump to

Keyboard shortcuts

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