41 lines
659 B
Go
41 lines
659 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"github.com/goccy/go-yaml"
|
|
"github.com/spf13/cobra"
|
|
|
|
"os"
|
|
)
|
|
|
|
func read(file string) []byte {
|
|
data, err := os.ReadFile(file)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return data
|
|
}
|
|
|
|
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 {
|
|
_, err := parse(read(arg))
|
|
if err != nil {
|
|
fmt.Printf("%s: %v\n", arg, err.Error())
|
|
}
|
|
}
|
|
return nil
|
|
}
|