command

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RegFormat         = regexp.MustCompile(`^(?P<name>\w+?)(?P<args>(?: [<\[]\w+?(?::\w+?)?[>\]](?:=\w+?)? ?)*)$`)
	ArgumentRegFormat = regexp.MustCompile(`(?:<(?P<required_name>\w+?)(?::(?P<required_type>\w+?))?>|\[(?P<optional_name>\w+?)(?::(?P<optional_type>\w+?))?\])(?:=(?P<default>\w+))?`)
	OptionRegFormat   = regexp.MustCompile(`^-(?P<short>\w+?) \[(?P<name>\w+?)(?::(?P<type>\w+?))?\](?:=(?P<default>\w+?))?$`)
)

Functions

func ParseCommand

func ParseCommand(test string) (name, last string)

Types

type Alias

type Alias map[string]map[string]string

type ArgType

type ArgType int
const (
	StringArg ArgType = iota
	TextArg
)

func ParseArgType

func ParseArgType(s string) (ArgType, error)

type Argument

type Argument struct {
	Type     ArgType
	Required bool
	Name     string
	Default  string
}

type Context

type Context struct {
	botc.MessageContext
	Tokens         []string
	Command        string
	ArgumentString string
	Args           map[string]string
	Options        map[string]string
}

func NewCommandContext

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

type FormatBuilder

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

func NewCommandFormatBuilder

func NewCommandFormatBuilder(format string, callback func(Inst) func()) *FormatBuilder

func (*FormatBuilder) Action

func (b *FormatBuilder) Action(handler func(ctx *Context)) *FormatBuilder

func (*FormatBuilder) Alias

func (b *FormatBuilder) Alias(reg string, option map[string]string) *FormatBuilder

func (*FormatBuilder) Arguments

func (b *FormatBuilder) Arguments(args string) *FormatBuilder

func (*FormatBuilder) Build

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

Build 构造命令

func (*FormatBuilder) Option

func (b *FormatBuilder) Option(opt string) *FormatBuilder

func (*FormatBuilder) SubCommand

func (b *FormatBuilder) SubCommand(format string) *FormatBuilder

SubCommand 创建子命令

type Inst

type Inst struct {
	Name      string
	Options   []Option
	Arguments []Argument
	Alias     map[string]map[string]string
	Subs      map[string]Inst
	// contains filtered or unexported fields
}

func (Inst) CheckAlias

func (i Inst) CheckAlias(cmdCtx *Context) error

func (Inst) Emit

func (i Inst) Emit(cmdCtx *Context) error

type Option

type Option struct {
	Type    ArgType
	Name    string
	Short   string
	Default string
}

type Registry

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

func NewCommandRegistry

func NewCommandRegistry(cmd Inst) *Registry

func (*Registry) CheckAlias

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

func (*Registry) Emit

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

type System

type System struct {
	Commands map[string]*Registry
	// contains filtered or unexported fields
}

func NewCommandSystem

func NewCommandSystem() *System

func (*System) Emit

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

func (*System) Register

func (s *System) Register(cmd Inst) func()

Jump to

Keyboard shortcuts

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