-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelp.go
More file actions
40 lines (33 loc) · 723 Bytes
/
help.go
File metadata and controls
40 lines (33 loc) · 723 Bytes
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
package main
import (
"flag"
"fmt"
"sort"
"strings"
"github.com/yuin/gopher-lua"
)
func printHelp(L *lua.LState) int {
fmt.Printf("Usage: blade [OPTION] [<target>] [<args>]\n")
fmt.Printf("\nOptions:\n")
flag.PrintDefaults()
fmt.Printf("\nTargets:\n")
// transform pretty prints the default key = "" (empty string)
transform := func(s string) string {
if s == "" {
return "<default>"
}
return s
}
// Sort and print targets
keys := make([]string, len(subcommands))
i := 0
for target := range subcommands {
keys[i] = target
i++
}
sort.Strings(keys)
for _, target := range keys {
fmt.Printf(" %v: %v\n", transform(target), strings.Trim(subcommands[target].help, "\n"))
}
return 0
}