Avoid manual step for creating array setters

This commit is contained in:
Phani Teja Marupaka
2020-06-15 17:18:38 -07:00
parent 3e9276271a
commit 0f0efe2a4c
9 changed files with 219 additions and 26 deletions

View File

@@ -91,7 +91,9 @@ func (r *CreateSetterRunner) preRunE(c *cobra.Command, args []string) error {
}
if setterVersion == "" {
if len(args) < 2 || !c.Flag("value").Changed && len(args) < 3 {
if len(args) == 2 && r.Set.SetPartialField.Type == "array" && c.Flag("field").Changed {
setterVersion = "v2"
} else if len(args) < 2 || !c.Flag("value").Changed && len(args) < 3 {
setterVersion = "v1"
} else if err := initSetterVersion(c, args); err != nil {
return err
@@ -124,6 +126,12 @@ func (r *CreateSetterRunner) preRunE(c *cobra.Command, args []string) error {
r.CreateSetter.Description = r.Set.SetPartialField.Description
r.CreateSetter.SetBy = r.Set.SetPartialField.SetBy
r.CreateSetter.Type = r.Set.SetPartialField.Type
if r.CreateSetter.Type == "array" {
// this is just a place holder value, we derive the actual value at
// later point from the field path
r.CreateSetter.FieldValue = "listValues"
}
}
return nil
}