Simple lint check for yaml files in the spirit of python -mjson.tool.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

34 lines
606 B

package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"gopkg.in/yaml.v2"
)
func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
b, err := ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintf(os.Stderr, "problem reading stdin: %v\n", err)
os.Exit(1)
}
var obj interface{}
err = yaml.Unmarshal(b, &obj)
if err != nil {
fmt.Fprintf(os.Stderr, "issue in decoding: %v\n", err)
os.Exit(1)
}
bs, err := yaml.Marshal(obj)
if err != nil {
fmt.Fprintf(os.Stderr, "issue in encoding: %v\n", err)
os.Exit(1)
}
r := bytes.NewReader(bs)
io.Copy(os.Stdout, r)
}