Skip to content

Commit 622b55a

Browse files
cahoonpworkJeff McCormick
authored andcommitted
added the ability to generate the pgo cli markdown for inclusion into the documentation (#601)
* updated links to gh-pages and added generated cli documents * add the ability to generate the pgo cli markdown for inclusion into the documentation * removed extra go get line
1 parent 8daa115 commit 622b55a

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ repo-client-image: check-go-vars
8383
foo: check-go-vars
8484
go install foo/foo.go
8585
mv $(GOBIN)/foo ./bin/foo/
86+
cli-docs: check-go-vars
87+
cd $(COROOT)/hugo/content/cli && go run $(COROOT)/pgo/generatedocs.go
8688
pgo: check-go-vars
8789
cd pgo && go install pgo.go
8890
clean: check-go-vars

bin/get-deps.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ fi
4040
echo "getting expenv go library..."
4141
go get github.com/blang/expenv
4242

43+
echo "getting go dependencies for cli markdown generation"
44+
go get github.com/cpuguy83/go-md2man/md2man
45+
go get github.com/spf13/cobra
46+
47+
4348
# uncomment only if you want to develop on the project
4449
#echo "getting all libraries for project..."
4550
#dep ensure

pgo/generatedocs.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+
log "github.com/Sirupsen/logrus"
6+
"path/filepath"
7+
"path"
8+
"strings"
9+
"github.com/spf13/cobra/doc"
10+
"github.com/crunchydata/postgres-operator/pgo/cmd"
11+
12+
)
13+
14+
const fmTemplate = `---
15+
title: "%s"
16+
---
17+
`
18+
19+
func main() {
20+
21+
fmt.Println("generate CLI markdown")
22+
23+
filePrepender := func(filename string) string {
24+
// now := time.Now().Format(time.RFC3339)
25+
name := filepath.Base(filename)
26+
base := strings.TrimSuffix(name, path.Ext(name))
27+
fmt.Println(base);
28+
// url := "/commands/" + strings.ToLower(base) + "/"
29+
return fmt.Sprintf(fmTemplate, base)
30+
}
31+
32+
linkHandler := func(name string) string {
33+
base := strings.TrimSuffix(name, path.Ext(name))
34+
return "/commands/" + strings.ToLower(base) + "/"
35+
}
36+
37+
err := doc.GenMarkdownTreeCustom(cmd.RootCmd, "./", filePrepender, linkHandler)
38+
if err != nil {
39+
log.Fatal(err)
40+
}
41+
}
42+
43+

0 commit comments

Comments
 (0)