pkg/process: only propagate missing keys to flags (#2784)

this avoids a problem where setting on a flag isn't sufficient
to express complex data structures like []string.

Change-Id: I06f13656996d658b4c7a957451cb253728a67eda
This commit is contained in:
Jeff Wendling 2019-08-14 14:41:41 -06:00 committed by JT Olio
parent 7db6851722
commit 2dab0ab466

View File

@ -187,8 +187,9 @@ func cleanup(cmd *cobra.Command) {
} }
} }
for key := range allKeys { // Propagate keys that are missing to flags, and remove any used keys
// Check if the key is a flag, and if so, propagate it. // from the missing set.
for key := range missingKeys {
if f := cmd.Flags().Lookup(key); f != nil { if f := cmd.Flags().Lookup(key); f != nil {
val := vip.GetString(key) val := vip.GetString(key)
err := f.Value.Set(val) err := f.Value.Set(val)
@ -206,12 +207,10 @@ func cleanup(cmd *cobra.Command) {
usedKeys[key] = struct{}{} usedKeys[key] = struct{}{}
} }
} }
}
// A key is only missing if it was missing from every single config struct, so for key := range missingKeys {
// remove all of the used keys from it.
if _, ok := usedKeys[key]; ok { if _, ok := usedKeys[key]; ok {
delete(missingKeys, key) delete(missingKeys, key)
continue
} }
} }