From 677f7d57ba23608d34dcf252a8a9935245573ccd Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Tue, 7 Jan 2025 09:20:15 +0100 Subject: [PATCH] fixed issue where nested was lost an in general nested maps did not work. --- cmd/yamldiff/yamldiff.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/yamldiff/yamldiff.go b/cmd/yamldiff/yamldiff.go index 42c12e4..50a079c 100644 --- a/cmd/yamldiff/yamldiff.go +++ b/cmd/yamldiff/yamldiff.go @@ -61,15 +61,19 @@ func subtract(yaml2 yaml.MapSlice, yaml1 yaml.MapSlice) yaml.MapSlice { v2 := item.Value v1 := yaml1.ToMap()[k] switch { + case v2 != nil && v1 == nil: + res = append(res, item) case reflect.DeepEqual(v1, v2): // delete is implicit by not copying to the output - case Type(v1) == Map && Type(v2) == Map: + case reflect.TypeOf(v1) == reflect.TypeOf(yaml.MapSlice{}) && + reflect.TypeOf(v2) == reflect.TypeOf(yaml.MapSlice{}): diff := subtract(v2.(yaml.MapSlice), v1.(yaml.MapSlice)) if len(diff) > 0 { - res = append(res, item) + mi := yaml.MapItem{Key: k, Value: diff} + res = append(res, mi) } case Type(v1) == Slice && Type(v2) == Slice: - + // To be improved can be really confusing. v2set := make(map[string]bool) v1set := make(map[string]bool) stringToValue := make(map[any]any) @@ -141,7 +145,7 @@ Shows the changes in compared to `, } cmd.PersistentFlags().IntVarP(&VERBOSITY, "array-output-level", - "v", 1, "Array output level: , 1: only show changed/added values, 2 (default) show identical as , 3: show all values") + "v", 1, "Array output level: , 1: only show changed/added values, 2 show identical as , 3: show all values") cmd.Execute() }