Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting copyright header file for generated completions #40023

Merged
merged 1 commit into from Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/cmd.go
Expand Up @@ -301,7 +301,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
Commands: []*cobra.Command{
NewCmdLabel(f, out),
NewCmdAnnotate(f, out),
NewCmdCompletion(f, out),
NewCmdCompletion(f, out, ""),
},
},
}
Expand Down
22 changes: 10 additions & 12 deletions pkg/kubectl/cmd/completion.go
Expand Up @@ -26,7 +26,7 @@ import (
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)

const boilerPlate = `
const defaultBoilerPlate = `
# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -86,7 +86,7 @@ var (
}
)

func NewCmdCompletion(f cmdutil.Factory, out io.Writer) *cobra.Command {
func NewCmdCompletion(f cmdutil.Factory, out io.Writer, boilerPlate string) *cobra.Command {
shells := []string{}
for s := range completion_shells {
shells = append(shells, s)
Expand All @@ -98,7 +98,7 @@ func NewCmdCompletion(f cmdutil.Factory, out io.Writer) *cobra.Command {
Long: completion_long,
Example: completion_example,
Run: func(cmd *cobra.Command, args []string) {
err := RunCompletion(out, cmd, args)
err := RunCompletion(out, boilerPlate, cmd, args)
cmdutil.CheckErr(err)
},
ValidArgs: shells,
Expand All @@ -107,7 +107,7 @@ func NewCmdCompletion(f cmdutil.Factory, out io.Writer) *cobra.Command {
return cmd
}

func RunCompletion(out io.Writer, cmd *cobra.Command, args []string) error {
func RunCompletion(out io.Writer, boilerPlate string, cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return cmdutil.UsageError(cmd, "Shell not specified.")
}
Expand All @@ -119,22 +119,20 @@ func RunCompletion(out io.Writer, cmd *cobra.Command, args []string) error {
return cmdutil.UsageError(cmd, "Unsupported shell type %q.", args[0])
}

if len(boilerPlate) == 0 {
boilerPlate = defaultBoilerPlate
}
if _, err := out.Write([]byte(boilerPlate)); err != nil {
return err
}
return run(out, cmd.Parent())
}

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 {
_, err := out.Write([]byte(boilerPlate))
if err != nil {
return err
}
zsh_initialization := `
__kubectl_bash_source() {
alias shopt=':'
Expand Down