cli/cmd/gen-docs/main.go
Mislav Marohnić 39080dc332 Generate help docs to GitHub Pages
`make site-docs`:
1. checks out the `gh-pages` branch into the `site/` directory;
2. regenerates `.md` help pages using Cobra;
3. commits and publishes updates.
2019-11-28 16:43:07 +01:00

43 lines
653 B
Go

package main
import (
"fmt"
"os"
"github.com/github/gh-cli/command"
"github.com/spf13/cobra/doc"
)
func main() {
if len(os.Args) < 2 {
fatal("Usage: gen-docs <destination-dir>")
}
dir := os.Args[1]
err := os.MkdirAll(dir, 0755)
if err != nil {
fatal(err)
}
err = doc.GenMarkdownTreeCustom(command.RootCmd, dir, filePrepender, linkHandler)
if err != nil {
fatal(err)
}
}
func filePrepender(filename string) string {
return `---
layout: page
---
`
}
func linkHandler(name string) string {
return fmt.Sprintf("{{site.baseurl}}{%% link %s %%}", name)
}
func fatal(msg interface{}) {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
}