summaryrefslogtreecommitdiffstats
path: root/cmd_help.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd_help.go')
-rw-r--r--cmd_help.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/cmd_help.go b/cmd_help.go
new file mode 100644
index 0000000..b14471c
--- /dev/null
+++ b/cmd_help.go
@@ -0,0 +1,32 @@
+package goctl
+
+import (
+ "fmt"
+ "sort"
+ "strings"
+)
+
+type cmdHelp struct{}
+
+func (cmd cmdHelp) Name() string {
+ return "help"
+}
+
+func (cmd cmdHelp) Help() string {
+ return "show this message"
+}
+
+func (cmd cmdHelp) Run(gc *Goctl, args []string) string {
+ rc := []string{"Available commands:", ""}
+ cmds := []string{}
+ for _, h := range gc.handlers {
+ cmds = append(cmds, fmt.Sprintf("\t%s\t%s", h.Name(), h.Help()))
+ }
+ sort.Strings(cmds)
+ rc = append(rc, cmds...)
+ return strings.Join(rc, "\n")
+}
+
+func init() {
+ builtinHandlers = append(builtinHandlers, cmdHelp{})
+}