feat: override state(former "enviroment") values via command-line args (#644)

The addition of `--set k1=v1,k2=v2` and `--values file1 --values file2` was originally planned in #361.

But it turned out we already had `--values` for existing helmfile commands like `sync`. Duplicated flags doesn't work, obviously.

So this actually add `--state-values-set k1=v1,k2=v2` and `--set-values-file file1 --set-values-file file2`.

They are called "state" values according to the discussion we had at #640

Resolves #361
This commit is contained in:
KUOKA Yusuke
2019-06-04 11:03:01 +09:00
committed by GitHub
parent e2d6dc4afa
commit 1d3f5f8a33
8 changed files with 191 additions and 11 deletions
+25
View File
@@ -48,3 +48,28 @@ func CastKeysToStrings(s interface{}) (map[string]interface{}, error) {
}
return new, nil
}
func Set(m map[string]interface{}, key []string, value string) map[string]interface{} {
if len(key) == 0 {
panic(fmt.Errorf("bug: unexpected length of key: %d", len(key)))
}
k := key[0]
if len(key) == 1 {
m[k] = value
return m
}
remain := key[1:]
nested, ok := m[k]
if !ok {
new_m := map[string]interface{}{}
nested = Set(new_m, remain, value)
}
m[k] = nested
return m
}