Merge pull request #35327 from r2d4/kubectl-completion-boilerplate
Automatic merge from submit-queue Add boilerplate to `kubectl completion bash` **What this PR does / why we need it**: Small refactor to make kubectl bash and zsh completion share boilerplate. Previously the boilerplate was not included in the bash script.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2014 The Kubernetes Authors.
|
Copyright 2016 The Kubernetes Authors.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -26,6 +26,22 @@ import (
|
|||||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const boilerPlate = `
|
||||||
|
# Copyright 2016 The Kubernetes Authors.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
`
|
||||||
|
|
||||||
var (
|
var (
|
||||||
completion_long = templates.LongDesc(`
|
completion_long = templates.LongDesc(`
|
||||||
Output shell completion code for the given shell (bash or zsh).
|
Output shell completion code for the given shell (bash or zsh).
|
||||||
@@ -93,24 +109,19 @@ func RunCompletion(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runCompletionBash(out io.Writer, kubectl *cobra.Command) error {
|
func runCompletionBash(out io.Writer, kubectl *cobra.Command) error {
|
||||||
|
_, err := out.Write([]byte(boilerPlate))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return kubectl.GenBashCompletion(out)
|
return kubectl.GenBashCompletion(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCompletionZsh(out io.Writer, kubectl *cobra.Command) error {
|
func runCompletionZsh(out io.Writer, kubectl *cobra.Command) error {
|
||||||
zsh_initialilzation := `# Copyright 2016 The Kubernetes Authors.
|
_, err := out.Write([]byte(boilerPlate))
|
||||||
#
|
if err != nil {
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
return err
|
||||||
# you may not use this file except in compliance with the License.
|
}
|
||||||
# You may obtain a copy of the License at
|
zsh_initialization := `
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
__kubectl_bash_source() {
|
__kubectl_bash_source() {
|
||||||
alias shopt=':'
|
alias shopt=':'
|
||||||
alias _expand=_bash_expand
|
alias _expand=_bash_expand
|
||||||
@@ -259,7 +270,7 @@ __kubectl_convert_bash_to_zsh() {
|
|||||||
-e "s/\\\$(type${RWORD}/\$(__kubectl_type/g" \
|
-e "s/\\\$(type${RWORD}/\$(__kubectl_type/g" \
|
||||||
<<'BASH_COMPLETION_EOF'
|
<<'BASH_COMPLETION_EOF'
|
||||||
`
|
`
|
||||||
out.Write([]byte(zsh_initialilzation))
|
out.Write([]byte(zsh_initialization))
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
kubectl.GenBashCompletion(buf)
|
kubectl.GenBashCompletion(buf)
|
||||||
|
|||||||
Reference in New Issue
Block a user