command

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckInputType added in v0.1.0

func CheckInputType(value string, inputType InputType) bool

func GetBool added in v0.1.0

func GetBool(value string) bool

func GetFloat added in v0.1.0

func GetFloat(value string) float64

func GetInt added in v0.1.0

func GetInt(value string) int

func RegisterInputType added in v0.1.0

func RegisterInputType(typeName InputType, checker *regexp.Regexp)

Types

type Context

type Context struct {
	botc.MessageContext

	Commands  []string
	Arguments []string
	KvArgs    map[string]string
	Options   map[string]string
	// contains filtered or unexported fields
}

func NewCommandContext

func NewCommandContext(msg botc.MessageContext, text string) *Context

func (*Context) AppendArg added in v0.1.0

func (ctx *Context) AppendArg(value string) error

func (*Context) Clone added in v0.1.0

func (ctx *Context) Clone() *Context

type FormatBuilder

type FormatBuilder struct {
	// contains filtered or unexported fields
}

func NewCommandFormatBuilder

func NewCommandFormatBuilder(name string, system *System) *FormatBuilder

func (*FormatBuilder) Action

func (f *FormatBuilder) Action(handler Handler) *FormatBuilder

func (*FormatBuilder) Alias

func (f *FormatBuilder) Alias(pattern string, transform func(*Context) *Context) *FormatBuilder

func (*FormatBuilder) Argument added in v0.1.0

func (f *FormatBuilder) Argument(name string, inputType InputType, required bool, help string) *FormatBuilder

func (*FormatBuilder) Build

func (f *FormatBuilder) Build() (func(), error)

func (*FormatBuilder) Description added in v0.1.0

func (f *FormatBuilder) Description(desc string) *FormatBuilder

func (*FormatBuilder) Option

func (f *FormatBuilder) Option(name string, shortName string, inputType InputType, required bool, Default string, help string) *FormatBuilder

func (*FormatBuilder) SubCommand

func (f *FormatBuilder) SubCommand(name string) *FormatBuilder

type Handler added in v0.1.0

type Handler = func(ctx *Context) error

type InputType added in v0.1.0

type InputType string
const (
	Number  InputType = "number"
	String  InputType = "string"
	Boolean InputType = "bool"
)

type ParsedArguments added in v0.1.0

type ParsedArguments = []string

type ParsedOptions added in v0.1.0

type ParsedOptions = map[string]string

type Registry

type Registry struct {
	Name          string
	Schema        Schema
	Handler       Handler
	Aliases       []alias
	SubRegistries []Registry
}

func (*Registry) CheckAlias

func (r *Registry) CheckAlias(ctx *Context)

func (*Registry) Emit

func (r *Registry) Emit(cmdCtx *Context) error

type Schema added in v0.1.0

type Schema struct {
	Name              string
	Description       string
	Options           []SchemaOption
	Arguments         []SchemaArgument
	SubCommandSchemas []Schema
}

func NewSchema added in v0.1.0

func NewSchema(name string) *Schema

func (*Schema) AddArgument added in v0.1.0

func (s *Schema) AddArgument(name string, inputType InputType, help string) *Schema

func (*Schema) AddOption added in v0.1.0

func (s *Schema) AddOption(short string, name string, inputType InputType, help string) *Schema

func (*Schema) AddSubCommandSchema added in v0.1.0

func (s *Schema) AddSubCommandSchema(schema Schema) *Schema

func (*Schema) Match added in v0.1.0

func (s *Schema) Match(token string) bool

type SchemaArgument added in v0.1.0

type SchemaArgument struct {
	Name     string
	Type     InputType
	Help     string
	Required bool
}

type SchemaOption added in v0.1.0

type SchemaOption struct {
	Name      string
	ShortName string
	Type      InputType
	Help      string
	Default   string
	Required  bool
}

type System

type System struct {
	// contains filtered or unexported fields
}

func NewCommandSystem

func NewCommandSystem() *System

func (*System) CheckAliases added in v0.1.0

func (s *System) CheckAliases(ctx *Context)

CheckAliases 遍历所有已注册命令检查别名匹配

func (*System) Emit

func (s *System) Emit(cmdCtx *Context)

func (*System) GetSchemas added in v0.1.0

func (s *System) GetSchemas() []Schema

GetSchemas 返回所有已注册的顶级命令 Schema

func (*System) Register

func (s *System) Register(registry Registry) func()

Jump to

Keyboard shortcuts

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