continue commands
This commit is contained in:
parent
181f2d2d2c
commit
1b0564b39a
6 changed files with 46 additions and 5 deletions
|
@ -55,7 +55,7 @@ func (cmd *command) Name() string {
|
||||||
return cmd.name
|
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 {
|
for i, v := range cmd.args {
|
||||||
if i > len(argValues)-1 {
|
if i > len(argValues)-1 {
|
||||||
|
|
30
src/CommandLib/command_context.go
Normal file
30
src/CommandLib/command_context.go
Normal 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()
|
||||||
|
}
|
4
src/CommandLib/command_definition.go
Normal file
4
src/CommandLib/command_definition.go
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
package commandlib
|
||||||
|
|
||||||
|
type CommandDefinition struct {
|
||||||
|
}
|
10
src/CommandLib/interface.go
Normal file
10
src/CommandLib/interface.go
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package commandlib
|
||||||
|
|
||||||
|
type Parameter interface {
|
||||||
|
Value() any
|
||||||
|
}
|
||||||
|
|
||||||
|
type Command interface {
|
||||||
|
Name() string
|
||||||
|
Parameters() []Parameter
|
||||||
|
}
|
|
@ -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 (^)
|
// All patterns are case-insensitive and must match the beginning of the input (^)
|
||||||
re, regexError := regexp.Compile(`(?i)^` + pattern.pattern)
|
re, regexError := regexp.Compile(`(?i)^` + pattern.pattern)
|
||||||
|
|
||||||
|
// If we encounter a regex error, stop tokenization ( wrongly defined pattern? )
|
||||||
if regexError != nil {
|
if regexError != nil {
|
||||||
tokens = nil
|
tokens = nil
|
||||||
err = regexError
|
err = regexError
|
||||||
|
|
|
@ -14,10 +14,6 @@ type Command interface {
|
||||||
Name() string
|
Name() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type argValue struct {
|
|
||||||
value string
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// testcmd, err := commandlib.CreateCommand(
|
// testcmd, err := commandlib.CreateCommand(
|
||||||
// "test",
|
// "test",
|
||||||
|
|
Loading…
Add table
Reference in a new issue