-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathgenerate.go
82 lines (63 loc) · 1.31 KB
/
generate.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
//go:generate go run generate.go
import (
"bytes"
"os"
"strings"
"text/template"
"github.com/spf13/cobra/doc"
"github.com/aws-cloudformation/rain/internal/cmd/rain"
"github.com/aws-cloudformation/rain/internal/console"
)
var tmpl *template.Template
func init() {
var err error
tmpl = template.New("README.tmpl")
tmpl = tmpl.Funcs(template.FuncMap{
"pad": func(s string, n int) string {
return strings.Repeat(" ", n-len(s))
},
})
if err != nil {
panic(err)
}
tmpl, err = tmpl.ParseFiles("README.tmpl")
if err != nil {
panic(err)
}
}
func emptyStr(s string) string {
return ""
}
func identity(s string) string {
if s == "rain.md" {
return "index.md"
}
return s
}
func main() {
console.NoColour = true
err := doc.GenMarkdownTreeCustom(rain.Cmd, "./", emptyStr, identity)
if err != nil {
panic(err)
}
err = os.Rename("rain.md", "index.md")
if err != nil {
panic(err)
}
// Generate usage
usage := bytes.Buffer{}
rain.Cmd.SetOut(&usage)
rain.Cmd.Usage()
// Generate README
buf := bytes.Buffer{}
err = tmpl.Execute(&buf, map[string]string{
"Usage": usage.String(),
})
if err != nil {
panic(err)
}
os.WriteFile("../README.md", buf.Bytes(), 0644)
rain.Cmd.GenBashCompletionFile("bash_completion.sh")
rain.Cmd.GenZshCompletionFile("zsh_completion.sh")
}