parser

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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(root any) (*CommandNode, error)

Parse parses a struct and returns a CommandNode tree.

Example:

type CLI struct {
	Serve ServeCmd `cmd:"serve"`
}
node, err := parser.Parse(&CLI{})

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