yamll: support reading from stdin.

This commit is contained in:
Kyle Isom 2016-07-05 15:54:13 -07:00
parent c8cdd70a08
commit 4720196aaa
2 changed files with 34 additions and 0 deletions

View File

@ -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.

View File

@ -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 {