X Tutup
Skip to content

Commit 9425d33

Browse files
authored
Merge pull request cli#127 from github/help-site
Generate help docs to GitHub Pages
2 parents 7c1390d + 39080dc commit 9425d33

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
bin/gh
1+
/bin
22
/gh-cli
33
.envrc
44
/dist
5+
/site

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,15 @@ bin/gh: $(BUILD_FILES)
1414

1515
test:
1616
go test ./...
17+
.PHONY: test
1718

18-
.PHONY: test
19+
site:
20+
git worktree add site gh-pages
21+
22+
site-docs: site
23+
git -C site rm 'gh*.md' 2>/dev/null || true
24+
go run ./cmd/gen-docs site
25+
git -C site add 'gh*.md'
26+
git -C site commit -m 'update help docs'
27+
git -C site push
28+
.PHONY: site-docs

cmd/gen-docs/main.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/github/gh-cli/command"
8+
"github.com/spf13/cobra/doc"
9+
)
10+
11+
func main() {
12+
if len(os.Args) < 2 {
13+
fatal("Usage: gen-docs <destination-dir>")
14+
}
15+
dir := os.Args[1]
16+
17+
err := os.MkdirAll(dir, 0755)
18+
if err != nil {
19+
fatal(err)
20+
}
21+
22+
err = doc.GenMarkdownTreeCustom(command.RootCmd, dir, filePrepender, linkHandler)
23+
if err != nil {
24+
fatal(err)
25+
}
26+
}
27+
28+
func filePrepender(filename string) string {
29+
return `---
30+
layout: page
31+
---
32+
33+
`
34+
}
35+
36+
func linkHandler(name string) string {
37+
return fmt.Sprintf("{{site.baseurl}}{%% link %s %%}", name)
38+
}
39+
40+
func fatal(msg interface{}) {
41+
fmt.Fprintln(os.Stderr, msg)
42+
os.Exit(1)
43+
}

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5
88
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
99
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
1010
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
11+
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
1112
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
1213
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1314
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -42,6 +43,7 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
4243
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
4344
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4445
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
46+
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
4547
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
4648
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
4749
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=

0 commit comments

Comments
 (0)
X Tutup