Merge pull request #32364 from aaronlehmann/preserve-env-order

cli: Preserve order of environment variables
This commit is contained in:
Vincent Demeester 2017-04-06 14:25:29 +02:00 committed by GitHub
commit fbddea6cac
1 changed files with 9 additions and 8 deletions

View File

@ -524,21 +524,22 @@ func updateLabels(flags *pflag.FlagSet, field *map[string]string) {
} }
func updateEnvironment(flags *pflag.FlagSet, field *[]string) { func updateEnvironment(flags *pflag.FlagSet, field *[]string) {
if flags.Changed(flagEnvAdd) {
envSet := map[string]string{} envSet := map[string]string{}
for _, v := range *field { for _, v := range *field {
envSet[envKey(v)] = v envSet[envKey(v)] = v
} }
if flags.Changed(flagEnvAdd) {
value := flags.Lookup(flagEnvAdd).Value.(*opts.ListOpts) value := flags.Lookup(flagEnvAdd).Value.(*opts.ListOpts)
for _, v := range value.GetAll() { for _, v := range value.GetAll() {
envSet[envKey(v)] = v envSet[envKey(v)] = v
} }
}
*field = []string{} *field = []string{}
for _, v := range envSet { for _, v := range envSet {
*field = append(*field, v) *field = append(*field, v)
} }
}
toRemove := buildToRemoveSet(flags, flagEnvRemove) toRemove := buildToRemoveSet(flags, flagEnvRemove)
*field = removeItems(*field, toRemove, envKey) *field = removeItems(*field, toRemove, envKey)