Skip to content

Commit

Permalink
Use the 'example' section of cobra commands
Browse files Browse the repository at this point in the history
This makes examples their own section in the docs, if they are defined.
  • Loading branch information
eparis committed Feb 20, 2015
1 parent c2c86b0 commit 781ca91
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cmd/gendocs/gen_kubectl_docs.go
Original file line number Diff line number Diff line change
@@ -31,9 +31,6 @@ import (
func printOptions(out *bytes.Buffer, command *cobra.Command, name string) {
flags := command.NonInheritedFlags()
flags.SetOutput(out)
if command.Runnable() {
fmt.Fprintf(out, "%s\n\n", command.UseLine())
}
if flags.HasFlags() {
fmt.Fprintf(out, "### Options\n\n```\n")
flags.PrintDefaults()
@@ -68,7 +65,16 @@ func genMarkdown(command *cobra.Command, parent, docsDir string) {
fmt.Fprintf(out, "## %s\n\n", name)
fmt.Fprintf(out, "%s\n\n", short)
fmt.Fprintf(out, "### Synopsis\n\n")
fmt.Fprintf(out, "%s\n\n", long)
fmt.Fprintf(out, "```\n%s\n```\n\n", long)

if command.Runnable() {
fmt.Fprintf(out, "%s\n\n", command.UseLine())
}

if len(command.Example) > 0 {
fmt.Fprintf(out, "### Examples\n\n")
fmt.Fprintf(out, "```\n%s\n```\n\n", command.Example)
}

printOptions(out, command, name)

5 changes: 5 additions & 0 deletions cmd/genman/gen_kubectl_man.go
Original file line number Diff line number Diff line change
@@ -133,6 +133,11 @@ func genMarkdown(command *cobra.Command, parent, docsDir string) {
preamble(out, name, short, long)
printOptions(out, command)

if len(command.Example) > 0 {
fmt.Fprintf(out, "# EXAMPLE\n")
fmt.Fprintf(out, "```\n%s\n```\n", command.Example)
}

if len(command.Commands()) > 0 || len(parent) > 0 {
fmt.Fprintf(out, "# SEE ALSO\n")
if len(parent) > 0 {

0 comments on commit 781ca91

Please sign in to comment.