command

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Name            string
	Description     string
	Commands        []*Command
	DynamicCommands func() []*Command
	Options         []*Option
	DynamicParam    *DynamicParam
	Run             func(cmd *ExecCmd)
}

func (*Command) AddCommand

func (cl *Command) AddCommand(cmds ...*Command)

func (*Command) Check

func (cl *Command) Check() error

func (*Command) Help

func (cl *Command) Help()

type DynamicParam

type DynamicParam struct {
	// input 当前最后输入的字符串用于支持模糊查询
	// return map[string]string key为值,value为描述
	Func        func(input string) []*Param
	Flag        string
	Description string
}

func (*DynamicParam) Check

func (dc *DynamicParam) Check() error

type ExecCmd

type ExecCmd struct {
	Name    string
	Child   *ExecCmd
	Parent  *ExecCmd
	Param   string
	Options map[string]string // 包含flag
	Command *Command
	Input   string
}

func ParseExecCommand

func ParseExecCommand(command []*Command, input string) (execCmd *ExecCmd)

func (*ExecCmd) Exec

func (ec *ExecCmd) Exec() bool

func (*ExecCmd) GetOption

func (ec *ExecCmd) GetOption(name string) (string, bool)

GetOption 支持忽略'-'前缀

type Flag

type Flag struct {
	Name        string
	Description string
}

func (*Flag) Check

func (f *Flag) Check() error

type Option

type Option struct {
	Name        string
	Description string
}

func (*Option) Check

func (p *Option) Check() error

type Param

type Param struct {
	Name        string
	Description string
	Extended    map[string]string
}

Jump to

Keyboard shortcuts

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