-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
129 lines (103 loc) · 2.61 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
"github.com/cli/cli/v2/internal/config"
"github.com/cli/cli/v2/internal/docs"
"github.com/cli/cli/v2/internal/gh"
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/pkg/cmd/root"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/extensions"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/spf13/pflag"
)
func main() {
if err := run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run(args []string) error {
flags := pflag.NewFlagSet("", pflag.ContinueOnError)
manPage := flags.BoolP("man-page", "", false, "Generate manual pages")
website := flags.BoolP("website", "", false, "Generate website pages")
dir := flags.StringP("doc-path", "", "", "Path directory where you want generate doc files")
help := flags.BoolP("help", "h", false, "Help about any command")
if err := flags.Parse(args); err != nil {
return err
}
if *help {
fmt.Fprintf(os.Stderr, "Usage of %s:\n\n%s", filepath.Base(args[0]), flags.FlagUsages())
return nil
}
if *dir == "" {
return fmt.Errorf("error: --doc-path not set")
}
ios, _, _, _ := iostreams.Test()
rootCmd, _ := root.NewCmdRoot(&cmdutil.Factory{
IOStreams: ios,
Browser: &browser{},
Config: func() (gh.Config, error) {
return config.NewFromString(""), nil
},
ExtensionManager: &em{},
}, "", "")
rootCmd.InitDefaultHelpCmd()
if err := os.MkdirAll(*dir, 0755); err != nil {
return err
}
if *website {
if err := docs.GenMarkdownTreeCustom(rootCmd, *dir, filePrepender, linkHandler); err != nil {
return err
}
}
if *manPage {
if err := docs.GenManTree(rootCmd, *dir); err != nil {
return err
}
}
return nil
}
func filePrepender(filename string) string {
return `---
layout: manual
permalink: /:path/:basename
---
`
}
func linkHandler(name string) string {
return fmt.Sprintf("./%s", strings.TrimSuffix(name, ".md"))
}
// Implements browser.Browser interface.
type browser struct{}
func (b *browser) Browse(_ string) error {
return nil
}
// Implements extensions.ExtensionManager interface.
type em struct{}
func (e *em) List() []extensions.Extension {
return nil
}
func (e *em) Install(_ ghrepo.Interface, _ string) error {
return nil
}
func (e *em) InstallLocal(_ string) error {
return nil
}
func (e *em) Upgrade(_ string, _ bool) error {
return nil
}
func (e *em) Remove(_ string) error {
return nil
}
func (e *em) Dispatch(_ []string, _ io.Reader, _, _ io.Writer) (bool, error) {
return false, nil
}
func (e *em) Create(_ string, _ extensions.ExtTemplateType) error {
return nil
}
func (e *em) EnableDryRunMode() {}