mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 04:59:25 -07:00
fix: module parameters are now sorted by name when using the 'help module' command
This commit is contained in:
parent
7a08366516
commit
5bf7814cba
1 changed files with 98 additions and 80 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -15,13 +16,7 @@ import (
|
|||
"github.com/bettercap/readline"
|
||||
)
|
||||
|
||||
func (s *Session) helpHandler(args []string, sess *Session) error {
|
||||
filter := ""
|
||||
if len(args) == 2 {
|
||||
filter = core.Trim(args[1])
|
||||
}
|
||||
|
||||
if filter == "" {
|
||||
func (s *Session) generalHelp() {
|
||||
fmt.Println()
|
||||
|
||||
maxLen := 0
|
||||
|
@ -59,8 +54,9 @@ func (s *Session) helpHandler(args []string, sess *Session) error {
|
|||
}
|
||||
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
} else {
|
||||
func (s *Session) moduleHelp(filter string) error {
|
||||
err, m := s.Module(filter)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -91,20 +87,42 @@ func (s *Session) helpHandler(args []string, sess *Session) error {
|
|||
|
||||
params := m.Parameters()
|
||||
if len(params) > 0 {
|
||||
fmt.Print(" Parameters\n\n")
|
||||
v := make([]*ModuleParam, 0)
|
||||
maxLen := 0
|
||||
for _, h := range params {
|
||||
len := len(h.Name)
|
||||
if len > maxLen {
|
||||
maxLen = len
|
||||
}
|
||||
v = append(v, h)
|
||||
}
|
||||
|
||||
for _, p := range params {
|
||||
sort.Slice(v, func(i, j int) bool {
|
||||
return v[i].Name < v[j].Name
|
||||
})
|
||||
|
||||
fmt.Print(" Parameters\n\n")
|
||||
for _, p := range v {
|
||||
fmt.Print(p.Help(maxLen))
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Session) helpHandler(args []string, sess *Session) error {
|
||||
filter := ""
|
||||
if len(args) == 2 {
|
||||
filter = core.Trim(args[1])
|
||||
}
|
||||
|
||||
if filter == "" {
|
||||
s.generalHelp()
|
||||
} else {
|
||||
if err := s.moduleHelp(filter); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue