Help us shape the future of Go! Take the 2026 Go Developer Survey

commandBase

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 30, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package commandBase 抽象的Command执行体结构,利用泛型提供多数据类型支持的Command解析、执行流程,约定Root节点为初始节点,不会参与执行匹配

@update 2024-07-18 05:25:13

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command[T any] struct {
	Name        string
	SubCommands map[string]*Command[T]
	Func        CommandFunc[T]
	Usage       string
	SupportArgs map[string]struct{}
	// contains filtered or unexported fields
}

Command Repeat

@author heyuhengmatt
@update 2024-07-18 04:43:37

func NewCommand

func NewCommand[T any](name string, fn CommandFunc[T]) *Command[T]

NewCommand 创建一个新的Command结构

@param name string
@param fn CommandFunc[T]
@return *Command
@author heyuhengmatt
@update 2024-07-18 05:29:58

func NewRootCommand

func NewRootCommand[T any](fn CommandFunc[T]) *Command[T]

NewCommand 创建一个新的Command结构

@param name string
@param fn CommandFunc[T]
@return *Command
@author heyuhengmatt
@update 2024-07-18 05:29:58

func (*Command[T]) AddArgs

func (c *Command[T]) AddArgs(args ...string) *Command[T]

AddArgs 添加一个SubCommand

@param c *Command[T]
@return AddUsage

func (*Command[T]) AddSubCommand

func (c *Command[T]) AddSubCommand(subCommand *Command[T]) *Command[T]

AddSubCommand 添加一个SubCommand

@param c *Command[T]
@return AddSubCommand
@author heyuhengmatt
@update 2024-07-18 05:30:07

func (*Command[T]) AddUsage

func (c *Command[T]) AddUsage(usage string) *Command[T]

AddUsage 添加一个SubCommand

@param c *Command[T]
@return AddUsage

func (*Command[T]) BuildChain

func (c *Command[T]) BuildChain()

BuildChain 从当前节点开始,执行Command

@param c *Command[T]
@return Execute
@author heyuhengmatt
@update 2024-07-18 05:30:21

func (*Command[T]) CheckUsage

func (c *Command[T]) CheckUsage(args ...string) (usage string, isHelp bool)

CheckUsage 获取当前节点的所有SubCommands

@param c
@return GetSubCommands

func (*Command[T]) Execute

func (c *Command[T]) Execute(ctx context.Context, data T, args []string) error

Execute 从当前节点开始,执行Command

@param c *Command[T]
@return Execute
@author heyuhengmatt
@update 2024-07-18 05:30:21

func (*Command[T]) FormatUsage

func (c *Command[T]) FormatUsage() string

FormatUsage 获取当前节点的所有SubCommands

@param c
@return GetSubCommands

func (*Command[T]) GetSubCommands

func (c *Command[T]) GetSubCommands() []string

GetSubCommands 获取当前节点的所有SubCommands

@param c
@return GetSubCommands

func (*Command[T]) GetSupportArgs

func (c *Command[T]) GetSupportArgs() []string

GetSupportArgs 获取当前节点的所有SubCommands

@param c
@return GetSubCommands

func (*Command[T]) Validate

func (c *Command[T]) Validate(ctx context.Context, data T, args []string) bool

Validate 从当前节点开始,执行Command

@param c *Command[T]
@return Execute
@author heyuhengmatt
@update 2024-07-18 05:30:21

type CommandFunc

type CommandFunc[T any] func(ctx context.Context, data T, args ...string) error

CommandFunc Repeat

@author heyuhengmatt
@update 2024-07-18 04:43:42

Jump to

Keyboard shortcuts

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