summaryrefslogtreecommitdiffstats
path: root/help.go
blob: b14471c305b0ee79a2514ca41a8b96531b6b0276 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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{})
}