continue commands

This commit is contained in:
Miroslav Vasilev 2025-06-17 16:17:00 +03:00
parent 181f2d2d2c
commit 1b0564b39a
6 changed files with 46 additions and 5 deletions

View file

@ -55,7 +55,7 @@ func (cmd *command) Name() string {
return cmd.name
}
func (cmd *command) DoWork(argValues []ArgumentValue) (err error) {
func (cmd *command) Execute(argValues []ArgumentValue) (err error) {
for i, v := range cmd.args {
if i > len(argValues)-1 {

View file

@ -0,0 +1,30 @@
package commandlib
type commandContext struct {
commandString string
tokens []Token
command Command
}
func CreateCommandContext(commandString string) (ctx *commandContext, err error) {
tokenizer := CreateTokenizer()
tokens, tokenizerError := tokenizer.Tokenize(commandString)
if tokenizerError != nil {
err = tokenizerError
return
}
ctx = &commandContext{
commandString: commandString,
tokens: tokens,
}
return
}
func (ctx *commandContext) Execute() (err error) {
ctx.command.Execute()
}

View file

@ -0,0 +1,4 @@
package commandlib
type CommandDefinition struct {
}

View file

@ -0,0 +1,10 @@
package commandlib
type Parameter interface {
Value() any
}
type Command interface {
Name() string
Parameters() []Parameter
}

View file

@ -126,6 +126,7 @@ func (t *tokenizer) Tokenize(commandMsg string) (tokens []Token, err error) {
// All patterns are case-insensitive and must match the beginning of the input (^)
re, regexError := regexp.Compile(`(?i)^` + pattern.pattern)
// If we encounter a regex error, stop tokenization ( wrongly defined pattern? )
if regexError != nil {
tokens = nil
err = regexError

View file

@ -14,10 +14,6 @@ type Command interface {
Name() string
}
type argValue struct {
value string
}
func main() {
// testcmd, err := commandlib.CreateCommand(
// "test",