Added the parse option to yamltool because it gives much better error messages than yuamllint and yq.

This commit is contained in:
Erik Brakkee 2025-11-30 17:11:11 +01:00
parent ef0ef6e215
commit 6162670570
3 changed files with 25 additions and 1 deletions

View File

@ -2,7 +2,11 @@ package main
import (
"bytes"
"fmt"
"github.com/goccy/go-yaml"
"github.com/spf13/cobra"
"os"
)
@ -24,3 +28,13 @@ func parse(data []byte) (yaml.MapSlice, error) {
}
return result, nil
}
func parseFiles(cmd *cobra.Command, args []string) error {
for _, arg := range args {
_, err := parse(read(arg))
if err != nil {
fmt.Printf("%s: %v\n", arg, err.Error())
}
}
return nil
}

View File

@ -57,6 +57,16 @@ Shows the additions and modifications in <file2> compared to <file1>`,
}
cmd.AddCommand(merge)
parse := &cobra.Command{
Use: "parse [file1] ... [fileN]",
Short: "Parse yaml files.",
Long: `Parse yaml files, usually gives better error messages than yamllint or yq`,
RunE: func(cmd *cobra.Command, args []string) error {
return parseFiles(cmd, args)
},
}
cmd.AddCommand(parse)
diff.PersistentFlags().IntVarP(&VERBOSITY, "array-output-level",
"v", 3, `Array output level: ,
0: no output, only exit status,

2
go.mod
View File

@ -1,6 +1,6 @@
module git.wamblee.org/public/gotools
go 1.23.4
go 1.24.7
require (
github.com/goccy/go-yaml v1.15.13