1 // Tomll is a linter for TOML
4 // cat file.toml | tomll > file_linted.toml
5 // tomll file1.toml file2.toml # lint the two files in place
15 "github.com/pelletier/go-toml"
20 fmt.Fprintln(os.Stderr, `tomll can be used in two ways:
21 Writing to STDIN and reading from STDOUT:
22 cat file.toml | tomll > file.toml
24 Reading and updating a list of files:
25 tomll a.toml b.toml c.toml
27 When given a list of files, tomll will modify all files in place without asking.
31 // read from stdin and print to stdout
33 s, err := lintReader(os.Stdin)
35 io.WriteString(os.Stderr, err.Error())
38 io.WriteString(os.Stdout, s)
40 // otherwise modify a list of files
41 for _, filename := range flag.Args() {
42 s, err := lintFile(filename)
44 io.WriteString(os.Stderr, err.Error())
47 ioutil.WriteFile(filename, []byte(s), 0644)
52 func lintFile(filename string) (string, error) {
53 tree, err := toml.LoadFile(filename)
57 return tree.String(), nil
60 func lintReader(r io.Reader) (string, error) {
61 tree, err := toml.LoadReader(r)
65 return tree.String(), nil