From 4720196aaa67f9cf29ff277a66b56c38a0c7d753 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Tue, 5 Jul 2016 15:54:13 -0700 Subject: [PATCH] yamll: support reading from stdin. --- cmd/yamll/README | 12 ++++++++++++ cmd/yamll/main.go | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/cmd/yamll/README b/cmd/yamll/README index 77b3559..3e71c5d 100644 --- a/cmd/yamll/README +++ b/cmd/yamll/README @@ -1,3 +1,15 @@ yamll: yaml linter Run this over YAML files to determine if they are well-formed or not. + +Usage: yamll [-hq] files... + + For each file, yamll will make sure it is a well-formatted YAML + file. Unless the -q option is passed, yamll will print the names + of each file and whether it was well-formed. With the -q option, + only malformed files are printed. + + If the only command line argument is "-", yamll will read from + standard input. It is assumed the entirety of standard input is + a single file. + diff --git a/cmd/yamll/main.go b/cmd/yamll/main.go index 8982348..8919876 100644 --- a/cmd/yamll/main.go +++ b/cmd/yamll/main.go @@ -42,6 +42,28 @@ func main() { os.Exit(0) } + if flag.NArg() == 1 && flag.Arg(0) == "-" { + path := "stdin" + in, err := ioutil.ReadAll(os.Stdin) + if err != nil { + errorf("%s FAILED: %s", path, err) + os.Exit(1) + } + + var e empty + err = yaml.Unmarshal(in, &e) + if err != nil { + errorf("%s FAILED: %s", path, err) + os.Exit(1) + } + + if !*quiet { + fmt.Printf("%s: OK\n", path) + } + + os.Exit(0) + } + for _, path := range flag.Args() { in, err := ioutil.ReadFile(path) if err != nil {