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() }