From 0497ffb9c69007ba2b4986809dd40a02d9996f94 Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Fri, 21 Oct 2016 14:04:46 -0700 Subject: [PATCH] Add boilerplate to kubectl completion bash Small refactor to make kubectl bash and zsh completion share boilerplate. Previously the boilerplate was not included in the bash script. --- pkg/kubectl/cmd/completion.go | 43 ++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/pkg/kubectl/cmd/completion.go b/pkg/kubectl/cmd/completion.go index 0bfb681837..f398dc7b53 100644 --- a/pkg/kubectl/cmd/completion.go +++ b/pkg/kubectl/cmd/completion.go @@ -1,5 +1,5 @@ /* -Copyright 2014 The Kubernetes Authors. +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. @@ -26,6 +26,22 @@ import ( 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 ( completion_long = templates.LongDesc(` 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 { + _, err := out.Write([]byte(boilerPlate)) + if err != nil { + return err + } return kubectl.GenBashCompletion(out) } func runCompletionZsh(out io.Writer, kubectl *cobra.Command) error { - zsh_initialilzation := `# 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. - + _, err := out.Write([]byte(boilerPlate)) + if err != nil { + return err + } + zsh_initialization := ` __kubectl_bash_source() { alias shopt=':' alias _expand=_bash_expand @@ -259,7 +270,7 @@ __kubectl_convert_bash_to_zsh() { -e "s/\\\$(type${RWORD}/\$(__kubectl_type/g" \ <<'BASH_COMPLETION_EOF' ` - out.Write([]byte(zsh_initialilzation)) + out.Write([]byte(zsh_initialization)) buf := new(bytes.Buffer) kubectl.GenBashCompletion(buf)