mirror of
https://github.com/bettercap/bettercap
synced 2025-07-06 13:02:12 -07:00
Cleaner handling of modules start/stop
This commit is contained in:
parent
1ee605d01d
commit
b1678b5902
6 changed files with 66 additions and 42 deletions
|
@ -15,12 +15,18 @@ type ModuleHandler struct {
|
|||
}
|
||||
|
||||
func NewModuleHandler(name string, expr string, desc string, exec func(args []string) error) ModuleHandler {
|
||||
return ModuleHandler{
|
||||
h := ModuleHandler{
|
||||
Name: name,
|
||||
Description: desc,
|
||||
Parser: regexp.MustCompile(expr),
|
||||
Parser: nil,
|
||||
Exec: exec,
|
||||
}
|
||||
|
||||
if expr != "" {
|
||||
h.Parser = regexp.MustCompile(expr)
|
||||
}
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
func (h *ModuleHandler) Help(padding int) string {
|
||||
|
@ -28,10 +34,18 @@ func (h *ModuleHandler) Help(padding int) string {
|
|||
}
|
||||
|
||||
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)]
|
||||
if h.Parser == nil {
|
||||
if line == h.Name {
|
||||
return true, nil
|
||||
} else {
|
||||
return false, nil
|
||||
}
|
||||
} else {
|
||||
return false, nil
|
||||
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