Skip to content

Commit 7511e93

Browse files
authored
Merge pull request kubernetes#71906 from Pingan2017/remove-deprecatedAlias
remove unused func deprecatedAlias
2 parents 9e29c3e + c1243dd commit 7511e93

File tree

3 files changed

+0
-70
lines changed

3 files changed

+0
-70
lines changed

pkg/kubectl/cmd/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ go_test(
8080
deps = [
8181
"//pkg/kubectl/cmd/util:go_default_library",
8282
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
83-
"//vendor/github.com/spf13/cobra:go_default_library",
8483
],
8584
)
8685

pkg/kubectl/cmd/cmd.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -572,18 +572,3 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
572572
func runHelp(cmd *cobra.Command, args []string) {
573573
cmd.Help()
574574
}
575-
576-
// deprecatedAlias is intended to be used to create a "wrapper" command around
577-
// an existing command. The wrapper works the same but prints a deprecation
578-
// message before running. This command is identical functionality.
579-
func deprecatedAlias(deprecatedVersion string, cmd *cobra.Command) *cobra.Command {
580-
// Have to be careful here because Cobra automatically extracts the name
581-
// of the command from the .Use field.
582-
originalName := cmd.Name()
583-
584-
cmd.Use = deprecatedVersion
585-
cmd.Deprecated = fmt.Sprintf("use %q instead", originalName)
586-
cmd.Short = fmt.Sprintf("%s. This command is deprecated, use %q instead", cmd.Short, originalName)
587-
cmd.Hidden = true
588-
return cmd
589-
}

pkg/kubectl/cmd/cmd_test.go

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@ limitations under the License.
1717
package cmd
1818

1919
import (
20-
"bytes"
2120
"fmt"
2221
"io/ioutil"
2322
"os"
2423
"reflect"
25-
"strings"
2624
"testing"
2725

28-
"github.com/spf13/cobra"
29-
3026
"k8s.io/cli-runtime/pkg/genericclioptions"
3127
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
3228
)
@@ -57,56 +53,6 @@ func TestNormalizationFuncGlobalExistence(t *testing.T) {
5753
}
5854
}
5955

60-
func Test_deprecatedAlias(t *testing.T) {
61-
var correctCommandCalled bool
62-
makeCobraCommand := func() *cobra.Command {
63-
cobraCmd := new(cobra.Command)
64-
cobraCmd.Use = "print five lines"
65-
cobraCmd.Run = func(*cobra.Command, []string) {
66-
correctCommandCalled = true
67-
}
68-
return cobraCmd
69-
}
70-
71-
original := makeCobraCommand()
72-
alias := deprecatedAlias("echo", makeCobraCommand())
73-
74-
if len(alias.Deprecated) == 0 {
75-
t.Error("deprecatedAlias should always have a non-empty .Deprecated")
76-
}
77-
if !strings.Contains(alias.Deprecated, "print") {
78-
t.Error("deprecatedAlias should give the name of the new function in its .Deprecated field")
79-
}
80-
if !alias.Hidden {
81-
t.Error("deprecatedAlias should never have .Hidden == false (deprecated aliases should be hidden)")
82-
}
83-
84-
if alias.Name() != "echo" {
85-
t.Errorf("deprecatedAlias has name %q, expected %q",
86-
alias.Name(), "echo")
87-
}
88-
if original.Name() != "print" {
89-
t.Errorf("original command has name %q, expected %q",
90-
original.Name(), "print")
91-
}
92-
93-
buffer := new(bytes.Buffer)
94-
alias.SetOutput(buffer)
95-
alias.Execute()
96-
str := buffer.String()
97-
if !strings.Contains(str, "deprecated") || !strings.Contains(str, "print") {
98-
t.Errorf("deprecation warning %q does not include enough information", str)
99-
}
100-
101-
// It would be nice to test to see that original.Run == alias.Run
102-
// Unfortunately Golang does not allow comparing functions. I could do
103-
// this with reflect, but that's technically invoking undefined
104-
// behavior. Best we can do is make sure that the function is called.
105-
if !correctCommandCalled {
106-
t.Errorf("original function doesn't appear to have been called by alias")
107-
}
108-
}
109-
11056
func TestKubectlCommandHandlesPlugins(t *testing.T) {
11157
tests := []struct {
11258
name string

0 commit comments

Comments
 (0)