kubectl: Validate flag usage against generators

This commit moves the generators into separate buckets and creates
separate calls for each one group. This helps in providing just the
necessary generators to each generator command.

Validation of flags against generators is also added so that flags
that are not meant to be used with a specific generator will result
in error.
This commit is contained in:
Michail Kargakis
2015-11-19 19:14:10 +01:00
parent 8b3c5f97ff
commit 71934b7643
7 changed files with 106 additions and 175 deletions

View File

@@ -101,7 +101,8 @@ func RunAutoscale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
// Get the generator, setup and validate all required parameters
generatorName := cmdutil.GetFlagString(cmd, "generator")
generator, found := f.Generator(generatorName)
generators := f.Generators("autoscale")
generator, found := generators[generatorName]
if !found {
return cmdutil.UsageError(cmd, fmt.Sprintf("generator %q not found.", generatorName))
}
@@ -117,6 +118,10 @@ func RunAutoscale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []
if err = kubectl.ValidateParams(names, params); err != nil {
return err
}
// Check for invalid flags used against the present generator.
if err := kubectl.EnsureFlagsValid(cmd, generators, generatorName); err != nil {
return err
}
// Generate new object
object, err := generator.Generate(params)