added yamltool sort
This commit is contained in:
+21
-6
@@ -2,10 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/goccy/go-yaml"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
"github.com/goccy/go-yaml"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// hack to be able to compare slices and dictionires that cannot be put into a map.
|
||||
@@ -45,6 +46,11 @@ func subtract(yaml2 yaml.MapSlice, yaml1 yaml.MapSlice) yaml.MapSlice {
|
||||
v1set[strval(v)] = true
|
||||
}
|
||||
s := make([]any, 0)
|
||||
// TODO
|
||||
// convert both slices to lists of strings
|
||||
// apply LCS to the list of strings with approximate equality
|
||||
// added elements: -> output fully
|
||||
// approximately equal elements: -> when identical, skip, otherwise, output diffs (recurse)
|
||||
for _, v2value := range v2.([]any) {
|
||||
k2 := strval(v2value)
|
||||
if v1set[k2] {
|
||||
@@ -78,13 +84,22 @@ func diff(cmd *cobra.Command, args []string) error {
|
||||
file1 := args[0]
|
||||
file2 := args[1]
|
||||
|
||||
yaml1, err := parse(read(file1))
|
||||
data1, err := read(file1)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("%s: %w", file1, err))
|
||||
return err
|
||||
}
|
||||
yaml2, err := parse(read(file2))
|
||||
data2, err := read(file2)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("%s: %w", file2, err))
|
||||
return err
|
||||
}
|
||||
|
||||
yaml1, err := parse(data1)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", file1, err)
|
||||
}
|
||||
yaml2, err := parse(data2)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", file2, err)
|
||||
}
|
||||
|
||||
diff1 := subtract(yaml2, yaml1)
|
||||
|
||||
Reference in New Issue
Block a user