@@ -161,15 +161,18 @@ func newSnapshotK8SCmd(out io.Writer) *cobra.Command {
161161 Example : snapshotK8SExample ,
162162 Args : func (cmd * cobra.Command , args []string ) error {
163163 configFileFlag := cmd .Flags ().Lookup ("config-file" )
164- hasConfigFile := configFileFlag != nil && configFileFlag .Changed
165- if hasConfigFile && len (args ) > 0 {
164+ if configFileFlag != nil && configFileFlag .Changed && o .configFilePath == "" {
165+ return fmt .Errorf ("cannot use '--config-file' with an empty value" )
166+ }
167+ useConfigFile := o .configFilePath != ""
168+ if useConfigFile && len (args ) > 0 {
166169 return fmt .Errorf ("cannot use '--config-file' together with a positional environment name argument" )
167170 }
168- if ! hasConfigFile && len (args ) == 0 {
171+ if ! useConfigFile && len (args ) == 0 {
169172 return fmt .Errorf ("requires either a positional environment name argument or --config-file" )
170173 }
171- if ! hasConfigFile && len (args ) > 1 {
172- return fmt .Errorf ("accepts at most 1 arg(s), received %d" , len (args ))
174+ if ! useConfigFile && len (args ) > 1 {
175+ return fmt .Errorf ("accepts 1 arg(s), received %d" , len (args ))
173176 }
174177 return nil
175178 },
@@ -180,8 +183,11 @@ func newSnapshotK8SCmd(out io.Writer) *cobra.Command {
180183 }
181184
182185 configFileFlag := cmd .Flags ().Lookup ("config-file" )
183- hasConfigFile := configFileFlag != nil && configFileFlag .Changed
184- if hasConfigFile {
186+ if configFileFlag != nil && configFileFlag .Changed && o .configFilePath == "" {
187+ return ErrorBeforePrintingUsage (cmd , "cannot use '--config-file' with an empty value" )
188+ }
189+ useConfigFile := o .configFilePath != ""
190+ if useConfigFile {
185191 namespaceFlagNames := []string {"namespaces" , "exclude-namespaces" , "namespaces-regex" , "exclude-namespaces-regex" }
186192 for _ , flagName := range namespaceFlagNames {
187193 if f := cmd .Flags ().Lookup (flagName ); f != nil && f .Changed {
@@ -191,7 +197,20 @@ func newSnapshotK8SCmd(out io.Writer) *cobra.Command {
191197 return nil
192198 }
193199
194- return MuXRequiredFlags (cmd , []string {"namespaces" , "exclude-namespaces" }, false )
200+ // Include vs exclude namespace flags mutual exclusion (all combinations)
201+ if err := MuXRequiredFlags (cmd , []string {"namespaces" , "exclude-namespaces" }, false ); err != nil {
202+ return err
203+ }
204+ if err := MuXRequiredFlags (cmd , []string {"namespaces" , "exclude-namespaces-regex" }, false ); err != nil {
205+ return err
206+ }
207+ if err := MuXRequiredFlags (cmd , []string {"namespaces-regex" , "exclude-namespaces" }, false ); err != nil {
208+ return err
209+ }
210+ if err := MuXRequiredFlags (cmd , []string {"namespaces-regex" , "exclude-namespaces-regex" }, false ); err != nil {
211+ return err
212+ }
213+ return nil
195214 },
196215 RunE : func (cmd * cobra.Command , args []string ) error {
197216 clientset , err := kube .NewK8sClientSet (o .kubeconfig )
0 commit comments