Update doc generation examples. Fixes #227.

This commit is contained in:
Garth Kidd 2016-01-17 11:29:42 +11:00
parent 8e6aca4182
commit 356750645f
2 changed files with 31 additions and 7 deletions

View file

@ -7,6 +7,7 @@ package main
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
) )
func main() { func main() {
@ -18,7 +19,7 @@ func main() {
Title: "MINE", Title: "MINE",
Section: "3", Section: "3",
} }
cmd.GenManTree(header, "/tmp") doc.GenManTree(cmd, header, "/tmp")
} }
``` ```

View file

@ -1,5 +1,26 @@
# Generating Markdown Docs For Your Own cobra.Command # Generating Markdown Docs For Your Own cobra.Command
Generating man pages from a cobra command is incredibly easy. An example is as follows:
```go
package main
import (
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
func main() {
cmd := &cobra.Command{
Use: "test",
Short: "my test program",
}
doc.GenMarkdownTree(cmd, "/tmp")
}
```
That will get you a Markdown document `/tmp/test.md`
## Generate markdown docs for the entire command tree ## Generate markdown docs for the entire command tree
This program can actually generate docs for the kubectl command in the kubernetes project This program can actually generate docs for the kubectl command in the kubernetes project
@ -11,13 +32,15 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd" kubectlcmd "k8s.io/kubernetes/pkg/kubectl/cmd"
"github.com/spf13/cobra/cobra" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"github.com/spf13/cobra/doc"
) )
func main() { func main() {
kubectl := cmd.NewFactory(nil).NewKubectlCommand(os.Stdin, ioutil.Discard, ioutil.Discard) cmd := kubectlcmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard)
doc.GenMarkdownTree(kubectl, "./") doc.GenMarkdownTree(cmd, "./")
} }
``` ```