From 25a72113b122f984c904b24c4af23a1cba1eff45 Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 4 Mar 2018 23:46:13 +0100 Subject: Add vendor files for spf13/viper --- .../github.com/pelletier/go-toml/cmd/tomll/main.go | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 vendor/github.com/pelletier/go-toml/cmd/tomll/main.go (limited to 'vendor/github.com/pelletier/go-toml/cmd/tomll') diff --git a/vendor/github.com/pelletier/go-toml/cmd/tomll/main.go b/vendor/github.com/pelletier/go-toml/cmd/tomll/main.go new file mode 100644 index 00000000..36c7e375 --- /dev/null +++ b/vendor/github.com/pelletier/go-toml/cmd/tomll/main.go @@ -0,0 +1,66 @@ +// Tomll is a linter for TOML +// +// Usage: +// cat file.toml | tomll > file_linted.toml +// tomll file1.toml file2.toml # lint the two files in place +package main + +import ( + "flag" + "fmt" + "io" + "io/ioutil" + "os" + + "github.com/pelletier/go-toml" +) + +func main() { + flag.Usage = func() { + fmt.Fprintln(os.Stderr, `tomll can be used in two ways: +Writing to STDIN and reading from STDOUT: + cat file.toml | tomll > file.toml + +Reading and updating a list of files: + tomll a.toml b.toml c.toml + +When given a list of files, tomll will modify all files in place without asking. +`) + } + flag.Parse() + // read from stdin and print to stdout + if flag.NArg() == 0 { + s, err := lintReader(os.Stdin) + if err != nil { + io.WriteString(os.Stderr, err.Error()) + os.Exit(-1) + } + io.WriteString(os.Stdout, s) + } else { + // otherwise modify a list of files + for _, filename := range flag.Args() { + s, err := lintFile(filename) + if err != nil { + io.WriteString(os.Stderr, err.Error()) + os.Exit(-1) + } + ioutil.WriteFile(filename, []byte(s), 0644) + } + } +} + +func lintFile(filename string) (string, error) { + tree, err := toml.LoadFile(filename) + if err != nil { + return "", err + } + return tree.String(), nil +} + +func lintReader(r io.Reader) (string, error) { + tree, err := toml.LoadReader(r) + if err != nil { + return "", err + } + return tree.String(), nil +} -- cgit v1.2.3