mirror of
https://github.com/bettercap/bettercap
synced 2025-07-15 01:23:42 -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
37
session/module_handler.go
Normal file
37
session/module_handler.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package session
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/evilsocket/bettercap/core"
|
||||
"regexp"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ModuleHandler struct {
|
||||
Name string
|
||||
Description string
|
||||
Parser *regexp.Regexp
|
||||
Exec func(args []string) error
|
||||
}
|
||||
|
||||
func NewModuleHandler(name string, expr string, desc string, exec func(args []string) error) ModuleHandler {
|
||||
return ModuleHandler{
|
||||
Name: name,
|
||||
Description: desc,
|
||||
Parser: regexp.MustCompile(expr),
|
||||
Exec: exec,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *ModuleHandler) Help(padding int) string {
|
||||
return fmt.Sprintf(" "+core.Bold("%"+strconv.Itoa(padding)+"s")+" : %s\n", h.Name, h.Description)
|
||||
}
|
||||
|
||||
func (h *ModuleHandler) 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