Make yamlfmt tool print filenames

Otherwise fixing errors YAML is much harder.
This commit is contained in:
Tim Hockin 2022-02-10 11:36:54 -08:00
parent f3654386ab
commit 722ebf8dca

View File

@ -18,6 +18,7 @@ package main
import ( import (
"flag" "flag"
"fmt"
"io" "io"
"os" "os"
@ -32,19 +33,23 @@ func main() {
for _, path := range flag.Args() { for _, path := range flag.Args() {
sourceYaml, err := os.ReadFile(path) sourceYaml, err := os.ReadFile(path)
if err != nil { if err != nil {
panic(err) fmt.Fprintf(os.Stderr, "%s: %v\n", path, err)
continue
} }
rootNode, err := fetchYaml(sourceYaml) rootNode, err := fetchYaml(sourceYaml)
if err != nil { if err != nil {
panic(err) fmt.Fprintf(os.Stderr, "%s: %v\n", path, err)
continue
} }
writer, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) writer, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil { if err != nil {
panic(err) fmt.Fprintf(os.Stderr, "%s: %v\n", path, err)
continue
} }
err = streamYaml(writer, indent, rootNode) err = streamYaml(writer, indent, rootNode)
if err != nil { if err != nil {
panic(err) fmt.Fprintf(os.Stderr, "%s: %v\n", path, err)
continue
} }
} }
} }