40 lines
684 B
Go
40 lines
684 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os"
|
|
|
|
"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
|
|
}
|
|
decoded, err := parse(data)
|
|
if err != nil {
|
|
fmt.Printf("%s: %v\n", arg, err.Error())
|
|
}
|
|
if len(args) > 1 {
|
|
fmt.Printf("---\n")
|
|
}
|
|
encode(os.Stdout, decoded)
|
|
}
|
|
return nil
|
|
}
|