From c1243ddd05b8ada606a0b1387ec414ba671abec6 Mon Sep 17 00:00:00 2001 From: Pingan2017 Date: Mon, 10 Dec 2018 16:08:32 +0800 Subject: [PATCH] remove unused func deprecatedAlias --- pkg/kubectl/cmd/BUILD | 1 - pkg/kubectl/cmd/cmd.go | 15 ----------- pkg/kubectl/cmd/cmd_test.go | 54 ------------------------------------- 3 files changed, 70 deletions(-) diff --git a/pkg/kubectl/cmd/BUILD b/pkg/kubectl/cmd/BUILD index 3672fe88d0..7636237e4c 100644 --- a/pkg/kubectl/cmd/BUILD +++ b/pkg/kubectl/cmd/BUILD @@ -79,7 +79,6 @@ go_test( deps = [ "//pkg/kubectl/cmd/util:go_default_library", "//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library", - "//vendor/github.com/spf13/cobra:go_default_library", ], ) diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 2cfe569e93..35e9e54cc0 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -555,18 +555,3 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command { func runHelp(cmd *cobra.Command, args []string) { cmd.Help() } - -// deprecatedAlias is intended to be used to create a "wrapper" command around -// an existing command. The wrapper works the same but prints a deprecation -// message before running. This command is identical functionality. -func deprecatedAlias(deprecatedVersion string, cmd *cobra.Command) *cobra.Command { - // Have to be careful here because Cobra automatically extracts the name - // of the command from the .Use field. - originalName := cmd.Name() - - cmd.Use = deprecatedVersion - cmd.Deprecated = fmt.Sprintf("use %q instead", originalName) - cmd.Short = fmt.Sprintf("%s. This command is deprecated, use %q instead", cmd.Short, originalName) - cmd.Hidden = true - return cmd -} diff --git a/pkg/kubectl/cmd/cmd_test.go b/pkg/kubectl/cmd/cmd_test.go index 34da43ebb0..2470b85b13 100644 --- a/pkg/kubectl/cmd/cmd_test.go +++ b/pkg/kubectl/cmd/cmd_test.go @@ -17,16 +17,12 @@ limitations under the License. package cmd import ( - "bytes" "fmt" "io/ioutil" "os" "reflect" - "strings" "testing" - "github.com/spf13/cobra" - "k8s.io/cli-runtime/pkg/genericclioptions" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" ) @@ -57,56 +53,6 @@ func TestNormalizationFuncGlobalExistence(t *testing.T) { } } -func Test_deprecatedAlias(t *testing.T) { - var correctCommandCalled bool - makeCobraCommand := func() *cobra.Command { - cobraCmd := new(cobra.Command) - cobraCmd.Use = "print five lines" - cobraCmd.Run = func(*cobra.Command, []string) { - correctCommandCalled = true - } - return cobraCmd - } - - original := makeCobraCommand() - alias := deprecatedAlias("echo", makeCobraCommand()) - - if len(alias.Deprecated) == 0 { - t.Error("deprecatedAlias should always have a non-empty .Deprecated") - } - if !strings.Contains(alias.Deprecated, "print") { - t.Error("deprecatedAlias should give the name of the new function in its .Deprecated field") - } - if !alias.Hidden { - t.Error("deprecatedAlias should never have .Hidden == false (deprecated aliases should be hidden)") - } - - if alias.Name() != "echo" { - t.Errorf("deprecatedAlias has name %q, expected %q", - alias.Name(), "echo") - } - if original.Name() != "print" { - t.Errorf("original command has name %q, expected %q", - original.Name(), "print") - } - - buffer := new(bytes.Buffer) - alias.SetOutput(buffer) - alias.Execute() - str := buffer.String() - if !strings.Contains(str, "deprecated") || !strings.Contains(str, "print") { - t.Errorf("deprecation warning %q does not include enough information", str) - } - - // It would be nice to test to see that original.Run == alias.Run - // Unfortunately Golang does not allow comparing functions. I could do - // this with reflect, but that's technically invoking undefined - // behavior. Best we can do is make sure that the function is called. - if !correctCommandCalled { - t.Errorf("original function doesn't appear to have been called by alias") - } -} - func TestKubectlCommandHandlesPlugins(t *testing.T) { tests := []struct { name string