35 lines
594 B
Go
35 lines
594 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"github.com/goccy/go-yaml"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func parse(data []byte) (yaml.MapSlice, error) {
|
|
var result yaml.MapSlice
|
|
decoder := yaml.NewDecoder(bytes.NewReader(data),
|
|
yaml.UseOrderedMap())
|
|
err := decoder.Decode(&result)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func parseFiles(cmd *cobra.Command, args []string) error {
|
|
for _, arg := range args {
|
|
data, err := read(arg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = parse(data)
|
|
if err != nil {
|
|
fmt.Printf("%s: %v\n", arg, err.Error())
|
|
}
|
|
}
|
|
return nil
|
|
}
|