sox/cmd_help.go
Waldo 0b2e83ba0c Fix test isolation bug and refactor command handling into plugins
Use unique user in unknown command test to avoid last-command fallback
interference. Add plugin architecture with registered commands.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 21:27:53 -07:00

37 lines
979 B
Go

package main
import (
"fmt"
"sort"
"strings"
)
type HelpPlugin struct{}
func (p HelpPlugin) Name() string { return "help" }
func (p HelpPlugin) ShortHelp() string { return "List commands or get help for a specific command" }
func (p HelpPlugin) DetailedHelp() string {
return "help [command]\n\nWith no arguments, lists all available commands.\nWith a command name, shows detailed help for that command.\n\nExamples:\n help\n help math"
}
func (p HelpPlugin) Execute(msg BotMessage, args string) string {
if args == "" {
names := make([]string, 0, len(registry))
for name := range registry {
names = append(names, name)
}
sort.Strings(names)
var sb strings.Builder
for _, name := range names {
fmt.Fprintf(&sb, "%s — %s\n", name, registry[name].ShortHelp())
}
return sb.String()
}
if plugin, ok := registry[args]; ok {
return plugin.DetailedHelp()
}
return fmt.Sprintf("No help found for '%s'. Try 'help' to see all commands.", args)
}