mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Use the 'example' section of cobra commands
This makes examples their own section in the docs, if they are defined.
This commit is contained in:
parent
c2c86b0a6d
commit
781ca91a59
@ -31,9 +31,6 @@ import (
|
|||||||
func printOptions(out *bytes.Buffer, command *cobra.Command, name string) {
|
func printOptions(out *bytes.Buffer, command *cobra.Command, name string) {
|
||||||
flags := command.NonInheritedFlags()
|
flags := command.NonInheritedFlags()
|
||||||
flags.SetOutput(out)
|
flags.SetOutput(out)
|
||||||
if command.Runnable() {
|
|
||||||
fmt.Fprintf(out, "%s\n\n", command.UseLine())
|
|
||||||
}
|
|
||||||
if flags.HasFlags() {
|
if flags.HasFlags() {
|
||||||
fmt.Fprintf(out, "### Options\n\n```\n")
|
fmt.Fprintf(out, "### Options\n\n```\n")
|
||||||
flags.PrintDefaults()
|
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", name)
|
||||||
fmt.Fprintf(out, "%s\n\n", short)
|
fmt.Fprintf(out, "%s\n\n", short)
|
||||||
fmt.Fprintf(out, "### Synopsis\n\n")
|
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)
|
printOptions(out, command, name)
|
||||||
|
|
||||||
|
@ -133,6 +133,11 @@ func genMarkdown(command *cobra.Command, parent, docsDir string) {
|
|||||||
preamble(out, name, short, long)
|
preamble(out, name, short, long)
|
||||||
printOptions(out, command)
|
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 {
|
if len(command.Commands()) > 0 || len(parent) > 0 {
|
||||||
fmt.Fprintf(out, "# SEE ALSO\n")
|
fmt.Fprintf(out, "# SEE ALSO\n")
|
||||||
if len(parent) > 0 {
|
if len(parent) > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user