From 781ca91a5975c72ed1719d3e29a5cddfc12872d2 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Fri, 20 Feb 2015 16:27:56 -0500 Subject: [PATCH] Use the 'example' section of cobra commands This makes examples their own section in the docs, if they are defined. --- cmd/gendocs/gen_kubectl_docs.go | 14 ++++++++++---- cmd/genman/gen_kubectl_man.go | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/gendocs/gen_kubectl_docs.go b/cmd/gendocs/gen_kubectl_docs.go index 3d628e6024c..e8d2ec72183 100644 --- a/cmd/gendocs/gen_kubectl_docs.go +++ b/cmd/gendocs/gen_kubectl_docs.go @@ -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) diff --git a/cmd/genman/gen_kubectl_man.go b/cmd/genman/gen_kubectl_man.go index 68878aba117..ec8f9cdbd61 100644 --- a/cmd/genman/gen_kubectl_man.go +++ b/cmd/genman/gen_kubectl_man.go @@ -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 {