mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #23801 from sttts/sttts-kubectl-completion-cmd
Automatic merge from submit-queue Move shell completion generation into 'kubectl completion' command Remove static shell completion scripts from the repo and add `completion` command to kubectl: ```bash $ source <(kubectl completion bash) ``` or ```bash $ source <(kubectl completion zsh) ``` This makes maintenance easier because no static scripts must be generated and committed anymore in the repo. Moreover, kubectl is self-contained again for the user including the latest completion code. I am thinking about the use-case of updating kubectl via gcloud (or some package manager). The completion code is always in-sync, without the need to download a `contrib/completion/bash/kubectl` file from github. Opinions are welcome /cc @eparis @nak3 Fixes https://github.com/openshift/origin/issues/5290 <!-- Reviewable:start --> --- This change is [<img src="http://reviewable.k8s.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](http://reviewable.k8s.io/reviews/kubernetes/kubernetes/23801) <!-- Reviewable:end -->
This commit is contained in:
commit
270e85960b
@ -1,5 +1,4 @@
|
||||
.generated_docs
|
||||
contrib/completions/bash/kubectl
|
||||
docs/admin/federation-apiserver.md
|
||||
docs/admin/federation-controller-manager.md
|
||||
docs/admin/kube-apiserver.md
|
||||
@ -14,6 +13,7 @@ docs/man/man1/kubectl-attach.1
|
||||
docs/man/man1/kubectl-autoscale.1
|
||||
docs/man/man1/kubectl-cluster-info-dump.1
|
||||
docs/man/man1/kubectl-cluster-info.1
|
||||
docs/man/man1/kubectl-completion.1
|
||||
docs/man/man1/kubectl-config-current-context.1
|
||||
docs/man/man1/kubectl-config-set-cluster.1
|
||||
docs/man/man1/kubectl-config-set-context.1
|
||||
@ -72,6 +72,7 @@ docs/user-guide/kubectl/kubectl_attach.md
|
||||
docs/user-guide/kubectl/kubectl_autoscale.md
|
||||
docs/user-guide/kubectl/kubectl_cluster-info.md
|
||||
docs/user-guide/kubectl/kubectl_cluster-info_dump.md
|
||||
docs/user-guide/kubectl/kubectl_completion.md
|
||||
docs/user-guide/kubectl/kubectl_config.md
|
||||
docs/user-guide/kubectl/kubectl_config_current-context.md
|
||||
docs/user-guide/kubectl/kubectl_config_set-cluster.md
|
||||
@ -127,6 +128,7 @@ docs/yaml/kubectl/kubectl_apply.yaml
|
||||
docs/yaml/kubectl/kubectl_attach.yaml
|
||||
docs/yaml/kubectl/kubectl_autoscale.yaml
|
||||
docs/yaml/kubectl/kubectl_cluster-info.yaml
|
||||
docs/yaml/kubectl/kubectl_completion.yaml
|
||||
docs/yaml/kubectl/kubectl_config.yaml
|
||||
docs/yaml/kubectl/kubectl_convert.yaml
|
||||
docs/yaml/kubectl/kubectl_cordon.yaml
|
||||
|
@ -478,7 +478,6 @@ function kube::build::source_targets() {
|
||||
test
|
||||
third_party
|
||||
vendor
|
||||
contrib/completions/bash/kubectl
|
||||
contrib/mesos
|
||||
.generated_docs
|
||||
)
|
||||
@ -1022,8 +1021,6 @@ function kube::release::package_full_tarball() {
|
||||
cp "${KUBE_ROOT}/README.md" "${release_stage}/"
|
||||
cp "${KUBE_ROOT}/Godeps/LICENSES" "${release_stage}/"
|
||||
cp "${KUBE_ROOT}/Vagrantfile" "${release_stage}/"
|
||||
mkdir -p "${release_stage}/contrib/completions/bash"
|
||||
cp "${KUBE_ROOT}/contrib/completions/bash/kubectl" "${release_stage}/contrib/completions/bash"
|
||||
|
||||
echo "${KUBE_GIT_VERSION}" > "${release_stage}/version"
|
||||
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"k8s.io/kubernetes/cmd/genutils"
|
||||
"k8s.io/kubernetes/pkg/kubectl/cmd"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// use os.Args instead of "flags" because "flags" will mess up the man pages!
|
||||
path := "contrib/completions/bash/"
|
||||
if len(os.Args) == 2 {
|
||||
path = os.Args[1]
|
||||
} else if len(os.Args) > 2 {
|
||||
fmt.Fprintf(os.Stderr, "usage: %s [output directory]\n", os.Args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
outDir, err := genutils.OutDir(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
outFile := outDir + "kubectl"
|
||||
|
||||
// TODO os.Stdin should really be something like ioutil.Discard, but a Reader
|
||||
kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard)
|
||||
kubectl.GenBashCompletionFile(outFile)
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
# Maintainers
|
||||
|
||||
Eric Paris <eparis@redhat.com>
|
||||
|
||||
|
||||
[]()
|
File diff suppressed because it is too large
Load Diff
152
docs/man/man1/kubectl-completion.1
Normal file
152
docs/man/man1/kubectl-completion.1
Normal file
@ -0,0 +1,152 @@
|
||||
.TH "KUBERNETES" "1" " kubernetes User Manuals" "Eric Paris" "Jan 2015" ""
|
||||
|
||||
|
||||
.SH NAME
|
||||
.PP
|
||||
kubectl completion \- Output shell completion code for the given shell (bash or zsh)
|
||||
|
||||
|
||||
.SH SYNOPSIS
|
||||
.PP
|
||||
\fBkubectl completion\fP [OPTIONS]
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
Output shell completion code for the given shell (bash or zsh).
|
||||
|
||||
.PP
|
||||
This command prints shell code which must be evaluation to provide interactive
|
||||
completion of kubectl commands.
|
||||
|
||||
|
||||
.SH OPTIONS INHERITED FROM PARENT COMMANDS
|
||||
.PP
|
||||
\fB\-\-alsologtostderr\fP=false
|
||||
log to standard error as well as files
|
||||
|
||||
.PP
|
||||
\fB\-\-api\-version\fP=""
|
||||
DEPRECATED: The API version to use when talking to the server
|
||||
|
||||
.PP
|
||||
\fB\-\-as\fP=""
|
||||
Username to impersonate for the operation.
|
||||
|
||||
.PP
|
||||
\fB\-\-certificate\-authority\fP=""
|
||||
Path to a cert. file for the certificate authority.
|
||||
|
||||
.PP
|
||||
\fB\-\-client\-certificate\fP=""
|
||||
Path to a client certificate file for TLS.
|
||||
|
||||
.PP
|
||||
\fB\-\-client\-key\fP=""
|
||||
Path to a client key file for TLS.
|
||||
|
||||
.PP
|
||||
\fB\-\-cluster\fP=""
|
||||
The name of the kubeconfig cluster to use
|
||||
|
||||
.PP
|
||||
\fB\-\-context\fP=""
|
||||
The name of the kubeconfig context to use
|
||||
|
||||
.PP
|
||||
\fB\-\-insecure\-skip\-tls\-verify\fP=false
|
||||
If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.
|
||||
|
||||
.PP
|
||||
\fB\-\-kubeconfig\fP=""
|
||||
Path to the kubeconfig file to use for CLI requests.
|
||||
|
||||
.PP
|
||||
\fB\-\-log\-backtrace\-at\fP=:0
|
||||
when logging hits line file:N, emit a stack trace
|
||||
|
||||
.PP
|
||||
\fB\-\-log\-dir\fP=""
|
||||
If non\-empty, write log files in this directory
|
||||
|
||||
.PP
|
||||
\fB\-\-log\-flush\-frequency\fP=5s
|
||||
Maximum number of seconds between log flushes
|
||||
|
||||
.PP
|
||||
\fB\-\-logtostderr\fP=true
|
||||
log to standard error instead of files
|
||||
|
||||
.PP
|
||||
\fB\-\-match\-server\-version\fP=false
|
||||
Require server version to match client version
|
||||
|
||||
.PP
|
||||
\fB\-\-namespace\fP=""
|
||||
If present, the namespace scope for this CLI request.
|
||||
|
||||
.PP
|
||||
\fB\-\-password\fP=""
|
||||
Password for basic authentication to the API server.
|
||||
|
||||
.PP
|
||||
\fB\-s\fP, \fB\-\-server\fP=""
|
||||
The address and port of the Kubernetes API server
|
||||
|
||||
.PP
|
||||
\fB\-\-stderrthreshold\fP=2
|
||||
logs at or above this threshold go to stderr
|
||||
|
||||
.PP
|
||||
\fB\-\-token\fP=""
|
||||
Bearer token for authentication to the API server.
|
||||
|
||||
.PP
|
||||
\fB\-\-user\fP=""
|
||||
The name of the kubeconfig user to use
|
||||
|
||||
.PP
|
||||
\fB\-\-username\fP=""
|
||||
Username for basic authentication to the API server.
|
||||
|
||||
.PP
|
||||
\fB\-\-v\fP=0
|
||||
log level for V logs
|
||||
|
||||
.PP
|
||||
\fB\-\-vmodule\fP=
|
||||
comma\-separated list of pattern=N settings for file\-filtered logging
|
||||
|
||||
|
||||
.SH EXAMPLE
|
||||
.PP
|
||||
.RS
|
||||
|
||||
.nf
|
||||
|
||||
$ source <(kubectl completion bash)
|
||||
|
||||
will load the kubectl completion code for bash. Note that this depends on the bash\-completion
|
||||
framework. It must be sourced before sourcing the kubectl completion, i.e. on the Mac:
|
||||
|
||||
$ brew install bash\-completion
|
||||
$ source $(brew \-\-prefix)/etc/bash\_completion
|
||||
$ source <(kubectl completion bash)
|
||||
|
||||
If you use zsh, the following will load kubectl zsh completion:
|
||||
|
||||
$ source <(kubectl completion zsh)
|
||||
|
||||
|
||||
.fi
|
||||
.RE
|
||||
|
||||
|
||||
.SH SEE ALSO
|
||||
.PP
|
||||
\fBkubectl(1)\fP,
|
||||
|
||||
|
||||
.SH HISTORY
|
||||
.PP
|
||||
January 2015, Originally compiled by Eric Paris (eparis at redhat dot com) based on the kubernetes source material, but hopefully they have been automatically generated since!
|
@ -120,7 +120,7 @@ Find more information at
|
||||
|
||||
.SH SEE ALSO
|
||||
.PP
|
||||
\fBkubectl\-get(1)\fP, \fBkubectl\-set(1)\fP, \fBkubectl\-describe(1)\fP, \fBkubectl\-create(1)\fP, \fBkubectl\-replace(1)\fP, \fBkubectl\-patch(1)\fP, \fBkubectl\-delete(1)\fP, \fBkubectl\-edit(1)\fP, \fBkubectl\-apply(1)\fP, \fBkubectl\-namespace(1)\fP, \fBkubectl\-logs(1)\fP, \fBkubectl\-rolling\-update(1)\fP, \fBkubectl\-scale(1)\fP, \fBkubectl\-cordon(1)\fP, \fBkubectl\-drain(1)\fP, \fBkubectl\-uncordon(1)\fP, \fBkubectl\-attach(1)\fP, \fBkubectl\-exec(1)\fP, \fBkubectl\-port\-forward(1)\fP, \fBkubectl\-proxy(1)\fP, \fBkubectl\-run(1)\fP, \fBkubectl\-stop(1)\fP, \fBkubectl\-expose(1)\fP, \fBkubectl\-autoscale(1)\fP, \fBkubectl\-rollout(1)\fP, \fBkubectl\-label(1)\fP, \fBkubectl\-annotate(1)\fP, \fBkubectl\-taint(1)\fP, \fBkubectl\-config(1)\fP, \fBkubectl\-cluster\-info(1)\fP, \fBkubectl\-api\-versions(1)\fP, \fBkubectl\-version(1)\fP, \fBkubectl\-explain(1)\fP, \fBkubectl\-convert(1)\fP,
|
||||
\fBkubectl\-get(1)\fP, \fBkubectl\-set(1)\fP, \fBkubectl\-describe(1)\fP, \fBkubectl\-create(1)\fP, \fBkubectl\-replace(1)\fP, \fBkubectl\-patch(1)\fP, \fBkubectl\-delete(1)\fP, \fBkubectl\-edit(1)\fP, \fBkubectl\-apply(1)\fP, \fBkubectl\-namespace(1)\fP, \fBkubectl\-logs(1)\fP, \fBkubectl\-rolling\-update(1)\fP, \fBkubectl\-scale(1)\fP, \fBkubectl\-cordon(1)\fP, \fBkubectl\-drain(1)\fP, \fBkubectl\-uncordon(1)\fP, \fBkubectl\-attach(1)\fP, \fBkubectl\-exec(1)\fP, \fBkubectl\-port\-forward(1)\fP, \fBkubectl\-proxy(1)\fP, \fBkubectl\-run(1)\fP, \fBkubectl\-stop(1)\fP, \fBkubectl\-expose(1)\fP, \fBkubectl\-autoscale(1)\fP, \fBkubectl\-rollout(1)\fP, \fBkubectl\-label(1)\fP, \fBkubectl\-annotate(1)\fP, \fBkubectl\-taint(1)\fP, \fBkubectl\-config(1)\fP, \fBkubectl\-cluster\-info(1)\fP, \fBkubectl\-api\-versions(1)\fP, \fBkubectl\-version(1)\fP, \fBkubectl\-explain(1)\fP, \fBkubectl\-convert(1)\fP, \fBkubectl\-completion(1)\fP,
|
||||
|
||||
|
||||
.SH HISTORY
|
||||
|
@ -83,6 +83,7 @@ kubectl
|
||||
* [kubectl attach](kubectl_attach.md) - Attach to a running container.
|
||||
* [kubectl autoscale](kubectl_autoscale.md) - Auto-scale a Deployment, ReplicaSet, or ReplicationController
|
||||
* [kubectl cluster-info](kubectl_cluster-info.md) - Display cluster info
|
||||
* [kubectl completion](kubectl_completion.md) - Output shell completion code for the given shell (bash or zsh)
|
||||
* [kubectl config](kubectl_config.md) - config modifies kubeconfig files
|
||||
* [kubectl convert](kubectl_convert.md) - Convert config files between different API versions
|
||||
* [kubectl cordon](kubectl_cordon.md) - Mark node as unschedulable
|
||||
@ -111,7 +112,7 @@ kubectl
|
||||
* [kubectl uncordon](kubectl_uncordon.md) - Mark node as schedulable
|
||||
* [kubectl version](kubectl_version.md) - Print the client and server version information.
|
||||
|
||||
###### Auto generated by spf13/cobra on 15-May-2016
|
||||
###### Auto generated by spf13/cobra on 30-May-2016
|
||||
|
||||
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||||
[]()
|
||||
|
102
docs/user-guide/kubectl/kubectl_completion.md
Normal file
102
docs/user-guide/kubectl/kubectl_completion.md
Normal file
@ -0,0 +1,102 @@
|
||||
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
|
||||
|
||||
<!-- BEGIN STRIP_FOR_RELEASE -->
|
||||
|
||||
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
||||
width="25" height="25">
|
||||
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
||||
width="25" height="25">
|
||||
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
||||
width="25" height="25">
|
||||
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
||||
width="25" height="25">
|
||||
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
|
||||
width="25" height="25">
|
||||
|
||||
<h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
|
||||
|
||||
If you are using a released version of Kubernetes, you should
|
||||
refer to the docs that go with that version.
|
||||
|
||||
Documentation for other releases can be found at
|
||||
[releases.k8s.io](http://releases.k8s.io).
|
||||
</strong>
|
||||
--
|
||||
|
||||
<!-- END STRIP_FOR_RELEASE -->
|
||||
|
||||
<!-- END MUNGE: UNVERSIONED_WARNING -->
|
||||
|
||||
## kubectl completion
|
||||
|
||||
Output shell completion code for the given shell (bash or zsh)
|
||||
|
||||
### Synopsis
|
||||
|
||||
|
||||
Output shell completion code for the given shell (bash or zsh).
|
||||
|
||||
This command prints shell code which must be evaluation to provide interactive
|
||||
completion of kubectl commands.
|
||||
|
||||
|
||||
```
|
||||
kubectl completion SHELL
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
```
|
||||
|
||||
$ source <(kubectl completion bash)
|
||||
|
||||
will load the kubectl completion code for bash. Note that this depends on the bash-completion
|
||||
framework. It must be sourced before sourcing the kubectl completion, i.e. on the Mac:
|
||||
|
||||
$ brew install bash-completion
|
||||
$ source $(brew --prefix)/etc/bash_completion
|
||||
$ source <(kubectl completion bash)
|
||||
|
||||
If you use zsh, the following will load kubectl zsh completion:
|
||||
|
||||
$ source <(kubectl completion zsh)
|
||||
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
--alsologtostderr[=false]: log to standard error as well as files
|
||||
--as="": Username to impersonate for the operation.
|
||||
--certificate-authority="": Path to a cert. file for the certificate authority.
|
||||
--client-certificate="": Path to a client certificate file for TLS.
|
||||
--client-key="": Path to a client key file for TLS.
|
||||
--cluster="": The name of the kubeconfig cluster to use
|
||||
--context="": The name of the kubeconfig context to use
|
||||
--insecure-skip-tls-verify[=false]: If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.
|
||||
--kubeconfig="": Path to the kubeconfig file to use for CLI requests.
|
||||
--log-backtrace-at=:0: when logging hits line file:N, emit a stack trace
|
||||
--log-dir="": If non-empty, write log files in this directory
|
||||
--log-flush-frequency=5s: Maximum number of seconds between log flushes
|
||||
--logtostderr[=true]: log to standard error instead of files
|
||||
--match-server-version[=false]: Require server version to match client version
|
||||
--namespace="": If present, the namespace scope for this CLI request.
|
||||
--password="": Password for basic authentication to the API server.
|
||||
-s, --server="": The address and port of the Kubernetes API server
|
||||
--stderrthreshold=2: logs at or above this threshold go to stderr
|
||||
--token="": Bearer token for authentication to the API server.
|
||||
--user="": The name of the kubeconfig user to use
|
||||
--username="": Username for basic authentication to the API server.
|
||||
--v=0: log level for V logs
|
||||
--vmodule=: comma-separated list of pattern=N settings for file-filtered logging
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
|
||||
|
||||
###### Auto generated by spf13/cobra on 30-May-2016
|
||||
|
||||
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||||
[]()
|
||||
<!-- END MUNGE: GENERATED_ANALYTICS -->
|
@ -100,3 +100,4 @@ see_also:
|
||||
- version
|
||||
- explain
|
||||
- convert
|
||||
- completion
|
||||
|
85
docs/yaml/kubectl/kubectl_completion.yaml
Normal file
85
docs/yaml/kubectl/kubectl_completion.yaml
Normal file
@ -0,0 +1,85 @@
|
||||
name: completion
|
||||
synopsis: |
|
||||
Output shell completion code for the given shell (bash or zsh)
|
||||
description: |
|
||||
Output shell completion code for the given shell (bash or zsh).
|
||||
|
||||
This command prints shell code which must be evaluation to provide interactive
|
||||
completion of kubectl commands.
|
||||
inherited_options:
|
||||
- name: alsologtostderr
|
||||
default_value: "false"
|
||||
usage: log to standard error as well as files
|
||||
- name: api-version
|
||||
usage: |
|
||||
DEPRECATED: The API version to use when talking to the server
|
||||
- name: as
|
||||
usage: Username to impersonate for the operation.
|
||||
- name: certificate-authority
|
||||
usage: Path to a cert. file for the certificate authority.
|
||||
- name: client-certificate
|
||||
usage: Path to a client certificate file for TLS.
|
||||
- name: client-key
|
||||
usage: Path to a client key file for TLS.
|
||||
- name: cluster
|
||||
usage: The name of the kubeconfig cluster to use
|
||||
- name: context
|
||||
usage: The name of the kubeconfig context to use
|
||||
- name: insecure-skip-tls-verify
|
||||
default_value: "false"
|
||||
usage: |
|
||||
If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.
|
||||
- name: kubeconfig
|
||||
usage: Path to the kubeconfig file to use for CLI requests.
|
||||
- name: log-backtrace-at
|
||||
default_value: :0
|
||||
usage: when logging hits line file:N, emit a stack trace
|
||||
- name: log-dir
|
||||
usage: If non-empty, write log files in this directory
|
||||
- name: log-flush-frequency
|
||||
default_value: 5s
|
||||
usage: Maximum number of seconds between log flushes
|
||||
- name: logtostderr
|
||||
default_value: "true"
|
||||
usage: log to standard error instead of files
|
||||
- name: match-server-version
|
||||
default_value: "false"
|
||||
usage: Require server version to match client version
|
||||
- name: namespace
|
||||
usage: If present, the namespace scope for this CLI request.
|
||||
- name: password
|
||||
usage: Password for basic authentication to the API server.
|
||||
- name: server
|
||||
shorthand: s
|
||||
usage: The address and port of the Kubernetes API server
|
||||
- name: stderrthreshold
|
||||
default_value: "2"
|
||||
usage: logs at or above this threshold go to stderr
|
||||
- name: token
|
||||
usage: Bearer token for authentication to the API server.
|
||||
- name: user
|
||||
usage: The name of the kubeconfig user to use
|
||||
- name: username
|
||||
usage: Username for basic authentication to the API server.
|
||||
- name: v
|
||||
default_value: "0"
|
||||
usage: log level for V logs
|
||||
- name: vmodule
|
||||
usage: |
|
||||
comma-separated list of pattern=N settings for file-filtered logging
|
||||
example: |2
|
||||
|
||||
$ source <(kubectl completion bash)
|
||||
|
||||
will load the kubectl completion code for bash. Note that this depends on the bash-completion
|
||||
framework. It must be sourced before sourcing the kubectl completion, i.e. on the Mac:
|
||||
|
||||
$ brew install bash-completion
|
||||
$ source $(brew --prefix)/etc/bash_completion
|
||||
$ source <(kubectl completion bash)
|
||||
|
||||
If you use zsh, the following will load kubectl zsh completion:
|
||||
|
||||
$ source <(kubectl completion zsh)
|
||||
see_also:
|
||||
- kubectl
|
@ -111,7 +111,6 @@ kube::golang::test_targets() {
|
||||
cmd/genman
|
||||
cmd/genyaml
|
||||
cmd/mungedocs
|
||||
cmd/genbashcomp
|
||||
cmd/genswaggertypedocs
|
||||
cmd/linkcheck
|
||||
examples/k8petstore/web-server/src
|
||||
|
@ -176,7 +176,7 @@ kube::util::find-binary() {
|
||||
echo -n "${bin}"
|
||||
}
|
||||
|
||||
# Run all known doc generators (today gendocs, genman, and genbashcomp for kubectl)
|
||||
# Run all known doc generators (today gendocs and genman for kubectl)
|
||||
# $1 is the directory to put those generated documents
|
||||
kube::util::gen-docs() {
|
||||
local dest="$1"
|
||||
@ -186,7 +186,6 @@ kube::util::gen-docs() {
|
||||
genkubedocs=$(kube::util::find-binary "genkubedocs")
|
||||
genman=$(kube::util::find-binary "genman")
|
||||
genyaml=$(kube::util::find-binary "genyaml")
|
||||
genbashcomp=$(kube::util::find-binary "genbashcomp")
|
||||
genfeddocs=$(kube::util::find-binary "genfeddocs")
|
||||
|
||||
mkdir -p "${dest}/docs/user-guide/kubectl/"
|
||||
@ -203,8 +202,6 @@ kube::util::gen-docs() {
|
||||
"${genman}" "${dest}/docs/man/man1/"
|
||||
mkdir -p "${dest}/docs/yaml/kubectl/"
|
||||
"${genyaml}" "${dest}/docs/yaml/kubectl/"
|
||||
mkdir -p "${dest}/contrib/completions/bash/"
|
||||
"${genbashcomp}" "${dest}/contrib/completions/bash/"
|
||||
|
||||
# create the list of generated files
|
||||
pushd "${dest}" > /dev/null
|
||||
|
@ -28,7 +28,6 @@ kube::golang::setup_env
|
||||
cmd/genkubedocs \
|
||||
cmd/genman \
|
||||
cmd/genyaml \
|
||||
cmd/genbashcomp \
|
||||
cmd/mungedocs \
|
||||
federation/cmd/genfeddocs
|
||||
|
||||
|
@ -28,7 +28,6 @@ kube::golang::setup_env
|
||||
cmd/genkubedocs \
|
||||
cmd/genman \
|
||||
cmd/genyaml \
|
||||
cmd/genbashcomp \
|
||||
cmd/mungedocs
|
||||
|
||||
# Find binary
|
||||
|
@ -235,6 +235,7 @@ Find more information at https://github.com/kubernetes/kubernetes.`,
|
||||
cmds.AddCommand(NewCmdVersion(f, out))
|
||||
cmds.AddCommand(NewCmdExplain(f, out))
|
||||
cmds.AddCommand(NewCmdConvert(f, out))
|
||||
cmds.AddCommand(NewCmdCompletion(f, out))
|
||||
|
||||
if cmds.Flag("namespace") != nil {
|
||||
if cmds.Flag("namespace").Annotations == nil {
|
||||
|
126
contrib/completions/zsh/kubectl → pkg/kubectl/cmd/completion.go
Executable file → Normal file
126
contrib/completions/zsh/kubectl → pkg/kubectl/cmd/completion.go
Executable file → Normal file
@ -1,6 +1,101 @@
|
||||
#!/bin/zsh
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
# Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
)
|
||||
|
||||
const (
|
||||
completion_long = `Output shell completion code for the given shell (bash or zsh).
|
||||
|
||||
This command prints shell code which must be evaluation to provide interactive
|
||||
completion of kubectl commands.
|
||||
`
|
||||
completion_example = `
|
||||
$ source <(kubectl completion bash)
|
||||
|
||||
will load the kubectl completion code for bash. Note that this depends on the bash-completion
|
||||
framework. It must be sourced before sourcing the kubectl completion, i.e. on the Mac:
|
||||
|
||||
$ brew install bash-completion
|
||||
$ source $(brew --prefix)/etc/bash_completion
|
||||
$ source <(kubectl completion bash)
|
||||
|
||||
If you use zsh, the following will load kubectl zsh completion:
|
||||
|
||||
$ source <(kubectl completion zsh)
|
||||
`
|
||||
)
|
||||
|
||||
var (
|
||||
completion_shells = map[string]func(out io.Writer, cmd *cobra.Command) error{
|
||||
"bash": runCompletionBash,
|
||||
"zsh": runCompletionZsh,
|
||||
}
|
||||
)
|
||||
|
||||
func NewCmdCompletion(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
shells := []string{}
|
||||
for s := range completion_shells {
|
||||
shells = append(shells, s)
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "completion SHELL",
|
||||
Short: "Output shell completion code for the given shell (bash or zsh)",
|
||||
Long: completion_long,
|
||||
Example: completion_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
err := RunCompletion(f, out, cmd, args)
|
||||
cmdutil.CheckErr(err)
|
||||
},
|
||||
ValidArgs: shells,
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func RunCompletion(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
return cmdutil.UsageError(cmd, "Shell not specified.")
|
||||
}
|
||||
if len(args) > 1 {
|
||||
return cmdutil.UsageError(cmd, "Too many arguments. Expected only the shell type.")
|
||||
}
|
||||
run, found := completion_shells[args[0]]
|
||||
if !found {
|
||||
return cmdutil.UsageError(cmd, "Unsupported shell type %q.", args[0])
|
||||
}
|
||||
|
||||
return run(out, cmd.Parent())
|
||||
}
|
||||
|
||||
func runCompletionBash(out io.Writer, kubectl *cobra.Command) error {
|
||||
return kubectl.GenBashCompletion(out)
|
||||
}
|
||||
|
||||
func runCompletionZsh(out io.Writer, kubectl *cobra.Command) error {
|
||||
zsh_initialilzation := `# Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -15,13 +110,13 @@
|
||||
# limitations under the License.
|
||||
|
||||
__kubectl_bash_source() {
|
||||
alias shopt=':'
|
||||
alias _expand=_bash_expand
|
||||
alias _complete=_bash_comp
|
||||
emulate -L sh
|
||||
setopt kshglob noshglob braceexpand
|
||||
alias shopt=':'
|
||||
alias _expand=_bash_expand
|
||||
alias _complete=_bash_comp
|
||||
emulate -L sh
|
||||
setopt kshglob noshglob braceexpand
|
||||
|
||||
source "$@"
|
||||
source "$@"
|
||||
}
|
||||
|
||||
__kubectl_type() {
|
||||
@ -160,5 +255,18 @@ __kubectl_bash_source <(sed \
|
||||
-e "s/${LWORD}compopt${RWORD}/__kubectl_compopt/g" \
|
||||
-e "s/${LWORD}declare${RWORD}/__kubectl_declare/g" \
|
||||
-e "s/\\\$(type${RWORD}/\$(__kubectl_type/g" \
|
||||
$(dirname $0)/../bash/kubectl
|
||||
<<'BASH_COMPLETION_EOF'
|
||||
`
|
||||
out.Write([]byte(zsh_initialilzation))
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
kubectl.GenBashCompletion(buf)
|
||||
out.Write(buf.Bytes())
|
||||
|
||||
zsh_tail := `
|
||||
BASH_COMPLETION_EOF
|
||||
)
|
||||
`
|
||||
out.Write([]byte(zsh_tail))
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user