-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (70 loc) · 1.64 KB
/
main.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
83
84
package main
import (
"fmt"
"os"
"strings"
"github.com/cli/cli/internal/docs"
"github.com/cli/cli/pkg/cmd/root"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/iostreams"
"github.com/spf13/pflag"
)
func main() {
var flagError pflag.ErrorHandling
docCmd := pflag.NewFlagSet("", flagError)
manPage := docCmd.BoolP("man-page", "", false, "Generate manual pages")
website := docCmd.BoolP("website", "", false, "Generate website pages")
dir := docCmd.StringP("doc-path", "", "", "Path directory where you want generate doc files")
help := docCmd.BoolP("help", "h", false, "Help about any command")
if err := docCmd.Parse(os.Args); err != nil {
os.Exit(1)
}
if *help {
_, err := fmt.Fprintf(os.Stderr, "Usage of %s:\n\n%s", os.Args[0], docCmd.FlagUsages())
if err != nil {
fatal(err)
}
os.Exit(1)
}
if *dir == "" {
fatal("no dir set")
}
io, _, _, _ := iostreams.Test()
rootCmd := root.NewCmdRoot(&cmdutil.Factory{IOStreams: io}, "", "")
err := os.MkdirAll(*dir, 0755)
if err != nil {
fatal(err)
}
if *website {
err = docs.GenMarkdownTreeCustom(rootCmd, *dir, filePrepender, linkHandler)
if err != nil {
fatal(err)
}
}
if *manPage {
header := &docs.GenManHeader{
Title: "gh",
Section: "1",
Source: "",
Manual: "",
}
err = docs.GenManTree(rootCmd, header, *dir)
if err != nil {
fatal(err)
}
}
}
func filePrepender(filename string) string {
return `---
layout: manual
permalink: /:path/:basename
---
`
}
func linkHandler(name string) string {
return fmt.Sprintf("./%s", strings.TrimSuffix(name, ".md"))
}
func fatal(msg interface{}) {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
}