mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Update doc generation examples. Fixes #227.
This commit is contained in:
parent
8e6aca4182
commit
356750645f
2 changed files with 31 additions and 7 deletions
|
@ -7,6 +7,7 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/cobra/doc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -18,7 +19,7 @@ func main() {
|
|||
Title: "MINE",
|
||||
Section: "3",
|
||||
}
|
||||
cmd.GenManTree(header, "/tmp")
|
||||
doc.GenManTree(cmd, header, "/tmp")
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -1,5 +1,26 @@
|
|||
# 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
|
||||
|
||||
This program can actually generate docs for the kubectl command in the kubernetes project
|
||||
|
@ -11,13 +32,15 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
|
||||
"github.com/spf13/cobra/cobra"
|
||||
kubectlcmd "k8s.io/kubernetes/pkg/kubectl/cmd"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
|
||||
"github.com/spf13/cobra/doc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
kubectl := cmd.NewFactory(nil).NewKubectlCommand(os.Stdin, ioutil.Discard, ioutil.Discard)
|
||||
doc.GenMarkdownTree(kubectl, "./")
|
||||
cmd := kubectlcmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard)
|
||||
doc.GenMarkdownTree(cmd, "./")
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -40,13 +63,13 @@ Both `GenMarkdown` and `GenMarkdownTree` have alternate versions with callbacks
|
|||
|
||||
```go
|
||||
func GenMarkdownTreeCustom(cmd *Command, dir string, filePrepender, linkHandler func(string) string) error {
|
||||
//...
|
||||
//...
|
||||
}
|
||||
```
|
||||
|
||||
```go
|
||||
func GenMarkdownCustom(cmd *Command, out *bytes.Buffer, linkHandler func(string) string) error {
|
||||
//...
|
||||
//...
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue