-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelp_allcommands.go
More file actions
70 lines (52 loc) · 1.31 KB
/
help_allcommands.go
File metadata and controls
70 lines (52 loc) · 1.31 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package warg
import (
"bufio"
"fmt"
"os"
"go.bbkane.com/warg/styles"
)
func allCmdsSectionHelp() Action {
return func(cmdCtx CmdContext) error {
file := cmdCtx.Stdout
f := bufio.NewWriter(file)
defer f.Flush()
s, err := conditionallyEnableStyle(false, cmdCtx.Flags, file)
if err != nil {
fmt.Fprintf(os.Stderr, "Error enabling color. Continuing without: %v\n", err)
}
p := styles.NewPrinter(file)
cur := cmdCtx.ParseState.CurrentSection
// Print top help section
if cur.HelpLong != "" {
p.Println(cur.HelpLong)
} else {
p.Println(cur.HelpShort)
}
p.Println()
p.Println(s.Header("All Commands") + " (use <cmd> -h to see flag details):")
p.Println()
path := []string{string(cmdCtx.App.Name)}
for _, e := range cmdCtx.ParseState.SectionPath {
path = append(path, string(e))
}
for _, flatSec := range depthFirstSections(*cur, path) {
for _, name := range flatSec.Sec.Cmds.SortedNames() {
com := flatSec.Sec.Cmds[name]
p.Print(" # ")
p.Println(com.HelpShort)
p.Print(" ")
for _, path := range flatSec.Path {
p.Print(s.CommandName(string(path)) + " ")
}
p.Println(s.CommandName(name))
p.Println()
}
}
if cur.Footer != "" {
p.Println(s.Header("Footer") + ":")
p.Println()
p.Println(cur.Footer)
}
return nil
}
}