-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelp_outline.go
More file actions
51 lines (40 loc) · 1.04 KB
/
help_outline.go
File metadata and controls
51 lines (40 loc) · 1.04 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
package warg
import (
"bufio"
"fmt"
"os"
"go.bbkane.com/warg/styles"
)
func outlineHelper(p *styles.Printer, s *styles.Styles, sec Section, indent int) {
// commands and command flags
for _, comName := range sec.Cmds.SortedNames() {
p.Println(
leftPad(s.CommandName(string(comName)), " ", indent),
)
}
// sections
for _, k := range sec.Sections.SortedNames() {
childSec := sec.Sections[k]
p.Println(
leftPad(s.SectionName(k), " ", indent),
)
outlineHelper(p, s, childSec, indent+1)
}
}
func outlineHelp() Cmd {
action := 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(f)
p.Println("# " + string(cmdCtx.App.RootSection.HelpShort))
p.Println(s.SectionName(string(cmdCtx.App.Name)))
outlineHelper(p, &s, cmdCtx.App.RootSection, 1)
return nil
}
return NewCmd("", action)
}