mirror of
https://github.com/bettercap/bettercap
synced 2025-07-11 15:46:59 -07:00
yeah i should have done this before, i know
This commit is contained in:
commit
0091ffdbb3
33 changed files with 25678 additions and 0 deletions
28
session/command_handler.go
Normal file
28
session/command_handler.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package session
|
||||
|
||||
import "regexp"
|
||||
|
||||
type CommandHandler struct {
|
||||
Name string
|
||||
Description string
|
||||
Parser *regexp.Regexp
|
||||
Exec func(args []string, s *Session) error
|
||||
}
|
||||
|
||||
func NewCommandHandler(name string, expr string, desc string, exec func(args []string, s *Session) error) CommandHandler {
|
||||
return CommandHandler{
|
||||
Name: name,
|
||||
Description: desc,
|
||||
Parser: regexp.MustCompile(expr),
|
||||
Exec: exec,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *CommandHandler) Parse(line string) (bool, []string) {
|
||||
result := h.Parser.FindStringSubmatch(line)
|
||||
if len(result) == h.Parser.NumSubexp()+1 {
|
||||
return true, result[1:len(result)]
|
||||
} else {
|
||||
return false, nil
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue