forked from roots/trellis-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
help.go
50 lines (40 loc) · 1.09 KB
/
help.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"bytes"
"fmt"
"sort"
"strings"
"github.com/mitchellh/cli"
)
func experimentalCommandHelpFunc(app string, f cli.HelpFunc) cli.HelpFunc {
return func(commands map[string]cli.CommandFactory) string {
var buf bytes.Buffer
if len(experimentalCommands) > 0 {
buf.WriteString("\n\nExperimental commands:\n")
}
maxKeyLen := 0
keys := make([]string, 0, len(experimentalCommands))
filteredCommands := make(map[string]cli.CommandFactory)
for key, command := range commands {
for _, experimentalKey := range experimentalCommands {
if key != experimentalKey {
filteredCommands[key] = command
}
}
}
for _, key := range experimentalCommands {
if len(key) > maxKeyLen {
maxKeyLen = len(key)
}
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
commandFunc, _ := commands[key]
command, _ := commandFunc()
key = fmt.Sprintf("%s%s", key, strings.Repeat(" ", maxKeyLen-len(key)))
buf.WriteString(fmt.Sprintf(" %s %s\n", key, command.Synopsis()))
}
return f(filteredCommands) + buf.String()
}
}