Browse code

disable --validate flag by default

deads2k authored on 2015/11/11 01:50:14
Showing 2 changed files
... ...
@@ -173,6 +173,14 @@ func changeSharedFlagDefaults(rootCmd *cobra.Command) {
173 173
 			showAllFlag.Changed = false
174 174
 			showAllFlag.Usage = "When printing, show all resources (false means hide terminated pods.)"
175 175
 		}
176
+
177
+		// we want to disable the --validate flag by default when we're running kube commands from oc.  We want to make sure
178
+		// that we're only getting the upstream --validate flags, so check both the flag and the usage
179
+		if validateFlag := currCmd.Flags().Lookup("validate"); (validateFlag != nil) && (validateFlag.Usage == "If true, use a schema to validate the input before sending it") {
180
+			validateFlag.DefValue = "false"
181
+			validateFlag.Value.Set("false")
182
+			validateFlag.Changed = false
183
+		}
176 184
 	}
177 185
 }
178 186
 
... ...
@@ -53,3 +53,29 @@ kubectlLoop:
53 53
 	}
54 54
 
55 55
 }
56
+
57
+// this only checks one level deep for nested commands, but it does ensure that we've gotten several
58
+// --validate flags.  Based on that we can reasonably assume we got them in the kube commands since they
59
+// all share the same registration.
60
+func TestValidateDisabled(t *testing.T) {
61
+	f := clientcmd.New(pflag.NewFlagSet("name", pflag.ContinueOnError))
62
+
63
+	oc := NewCommandCLI("oc", "oc", &bytes.Buffer{}, ioutil.Discard, ioutil.Discard)
64
+	kubectl := kcmd.NewKubectlCommand(f.Factory, nil, ioutil.Discard, ioutil.Discard)
65
+
66
+	for _, kubecmd := range kubectl.Commands() {
67
+		for _, occmd := range oc.Commands() {
68
+			if kubecmd.Name() == occmd.Name() {
69
+				ocValidateFlag := occmd.Flags().Lookup("validate")
70
+				if ocValidateFlag == nil {
71
+					continue
72
+				}
73
+
74
+				if ocValidateFlag.Value.String() != "false" {
75
+					t.Errorf("%s --validate is not defaulting to false", occmd.Name())
76
+				}
77
+			}
78
+		}
79
+	}
80
+
81
+}