mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +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) {
|
||||
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)
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user