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..5f06a651ff7 100644 --- a/cmd/genman/gen_kubectl_man.go +++ b/cmd/genman/gen_kubectl_man.go @@ -100,18 +100,18 @@ func printFlags(out *bytes.Buffer, flags *pflag.FlagSet) { } func printOptions(out *bytes.Buffer, command *cobra.Command) { - var flags *pflag.FlagSet - if command.HasFlags() { - flags = command.Flags() - } else if !command.HasParent() && command.HasPersistentFlags() { - flags = command.PersistentFlags() + flags := command.NonInheritedFlags() + if flags.HasFlags() { + fmt.Fprintf(out, "# OPTIONS\n") + printFlags(out, flags) + fmt.Fprintf(out, "\n") } - if flags == nil { - return + flags = command.InheritedFlags() + if flags.HasFlags() { + fmt.Fprintf(out, "# OPTIONS INHERITED FROM PARENT COMMANDS\n") + printFlags(out, flags) + fmt.Fprintf(out, "\n") } - fmt.Fprintf(out, "# OPTIONS\n") - printFlags(out, flags) - fmt.Fprintf(out, "\n") } func genMarkdown(command *cobra.Command, parent, docsDir string) { @@ -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 { diff --git a/docs/kubectl-config-set-cluster.md b/docs/kubectl-config-set-cluster.md index 858a250b658..59d2f363ed0 100644 --- a/docs/kubectl-config-set-cluster.md +++ b/docs/kubectl-config-set-cluster.md @@ -4,12 +4,14 @@ Sets a cluster entry in .kubeconfig ### Synopsis +``` Sets a cluster entry in .kubeconfig Specifying a name that already exists will merge new fields on top of existing values for those fields. e.g. kubectl config set-cluster e2e --certificate-authority=~/.kube/e2e/.kubernetes.ca.cert only sets the certificate-authority field on the e2e cluster entry without touching other values. +``` kubectl config set-cluster name [--server=server] [--certificate-authority=path/to/certficate/authority] [--api-version=apiversion] [--insecure-skip-tls-verify=true] diff --git a/docs/kubectl-config-set-context.md b/docs/kubectl-config-set-context.md index f0c9740705b..b68f357c4c1 100644 --- a/docs/kubectl-config-set-context.md +++ b/docs/kubectl-config-set-context.md @@ -4,12 +4,13 @@ Sets a context entry in .kubeconfig ### Synopsis +``` Sets a context entry in .kubeconfig Specifying a name that already exists will merge new fields on top of existing values for those fields. e.g. kubectl config set-context gce --user=cluster-admin only sets the user field on the gce context entry without touching other values. - +``` kubectl config set-context name [--cluster=cluster-nickname] [--user=user-nickname] [--namespace=namespace] diff --git a/docs/kubectl-config-set-credentials.md b/docs/kubectl-config-set-credentials.md index 3bde7a29593..cf9de7eee4e 100644 --- a/docs/kubectl-config-set-credentials.md +++ b/docs/kubectl-config-set-credentials.md @@ -4,6 +4,7 @@ Sets a user entry in .kubeconfig ### Synopsis +``` Sets a user entry in .kubeconfig Specifying a name that already exists will merge new fields on top of existing @@ -23,6 +24,7 @@ Sets a user entry in .kubeconfig Bearer token and basic auth are mutually exclusive. +``` kubectl config set-credentials name [--auth-path=authfile] [--client-certificate=certfile] [--client-key=keyfile] [--token=bearer_token] [--username=basic_user] [--password=basic_password] diff --git a/docs/kubectl-config-set.md b/docs/kubectl-config-set.md index ec1407ed81e..dd86268e849 100644 --- a/docs/kubectl-config-set.md +++ b/docs/kubectl-config-set.md @@ -4,12 +4,14 @@ Sets an individual value in a .kubeconfig file ### Synopsis +``` Sets an individual value in a .kubeconfig file property-name is a dot delimited name where each token represents either a attribute name or a map key. Map keys may not contain dots. property-value is the new value you wish to set. +``` kubectl config set property-name property-value diff --git a/docs/kubectl-config-unset.md b/docs/kubectl-config-unset.md index 52fac25c36a..72b00656a0b 100644 --- a/docs/kubectl-config-unset.md +++ b/docs/kubectl-config-unset.md @@ -4,10 +4,12 @@ Unsets an individual value in a .kubeconfig file ### Synopsis +``` Unsets an individual value in a .kubeconfig file property-name is a dot delimited name where each token represents either a attribute name or a map key. Map keys may not contain dots. +``` kubectl config unset property-name diff --git a/docs/kubectl-config-use-context.md b/docs/kubectl-config-use-context.md index 6d4c2e9e29b..8b152554b38 100644 --- a/docs/kubectl-config-use-context.md +++ b/docs/kubectl-config-use-context.md @@ -4,7 +4,9 @@ Sets the current-context in a .kubeconfig file ### Synopsis +``` Sets the current-context in a .kubeconfig file +``` kubectl config use-context context-name diff --git a/docs/kubectl-config-view.md b/docs/kubectl-config-view.md index 4dd3647710a..037bb63795a 100644 --- a/docs/kubectl-config-view.md +++ b/docs/kubectl-config-view.md @@ -4,16 +4,22 @@ displays merged .kubeconfig settings or a specified .kubeconfig file. ### Synopsis +``` displays merged .kubeconfig settings or a specified .kubeconfig file. -Examples: - // Show merged .kubeconfig settings. - $ kubectl config view - - // Show only local ./.kubeconfig settings - $ kubectl config view --local +``` kubectl config view +### Examples + +``` +// Show merged .kubeconfig settings. +$ kubectl config view + +// Show only local ./.kubeconfig settings +$ kubectl config view --local +``` + ### Options ``` diff --git a/docs/kubectl-config.md b/docs/kubectl-config.md index 4a13f087719..aac77726be7 100644 --- a/docs/kubectl-config.md +++ b/docs/kubectl-config.md @@ -4,7 +4,9 @@ config modifies .kubeconfig files ### Synopsis +``` config modifies .kubeconfig files using subcommands like "kubectl config set current-context my-context" +``` kubectl config diff --git a/docs/kubectl-create.md b/docs/kubectl-create.md index 3a1d5d28097..63e08787add 100644 --- a/docs/kubectl-create.md +++ b/docs/kubectl-create.md @@ -4,20 +4,24 @@ Create a resource by filename or stdin ### Synopsis +``` Create a resource by filename or stdin. JSON and YAML formats are accepted. - -Examples: - - // Create a pod using the data in pod.json. - $ kubectl create -f pod.json - - // Create a pod based on the JSON passed into stdin. - $ cat pod.json | kubectl create -f - +``` kubectl create -f filename +### Examples + +``` +// Create a pod using the data in pod.json. +$ kubectl create -f pod.json + +// Create a pod based on the JSON passed into stdin. +$ cat pod.json | kubectl create -f - +``` + ### Options ``` diff --git a/docs/kubectl-delete.md b/docs/kubectl-delete.md index 66605befda5..470e042dd4a 100644 --- a/docs/kubectl-delete.md +++ b/docs/kubectl-delete.md @@ -4,6 +4,7 @@ Delete a resource by filename, stdin, or resource and ID. ### Synopsis +``` Delete a resource by filename, stdin, resource and ID, or by resources and label selector. JSON and YAML formats are accepted. @@ -14,26 +15,29 @@ arguments are used and the filename is ignored. Note that the delete command does NOT do resource version checks, so if someone submits an update to a resource right when you submit a delete, their update will be lost along with the rest of the resource. - -Examples: - - // Delete a pod using the type and ID specified in pod.json. - $ kubectl delete -f pod.json - - // Delete a pod based on the type and ID in the JSON passed into stdin. - $ cat pod.json | kubectl delete -f - - - // Delete pods and services with label name=myLabel. - $ kubectl delete pods,services -l name=myLabel - - // Delete a pod with ID 1234-56-7890-234234-456456. - $ kubectl delete pod 1234-56-7890-234234-456456 - - // Delete all pods - $ kubectl delete pods --all +``` kubectl delete ([-f filename] | ( [( | -l