commit 3dfe7ec69df42e42ead9f1361eb54e029b8b4aff Author: Martin Lindhe Date: Tue Jul 12 14:32:37 2016 +0200 initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a5ff228 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Martin Lindhe + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fbb7aca --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# About + +[![gorelease](https://dn-gorelease.qbox.me/gorelease-download-blue.svg)](https://gobuild.io/martinlindhe/validtoml/master) + +Command line tool to validate TOML syntax of input file. + + +# Installation + + go get -u github.com/martinlindhe/validtoml + + +# Usage + +Exit code will be 0 if file is good. + + validtoml file.toml + + OK: file.toml + + +# License + +Under [MIT](LICENSE) diff --git a/examples/invalid-key-open-bracket.toml b/examples/invalid-key-open-bracket.toml new file mode 100644 index 0000000..f0aeb16 --- /dev/null +++ b/examples/invalid-key-open-bracket.toml @@ -0,0 +1 @@ +[abc = 1 diff --git a/examples/valid-arrays.toml b/examples/valid-arrays.toml new file mode 100644 index 0000000..c435f57 --- /dev/null +++ b/examples/valid-arrays.toml @@ -0,0 +1,8 @@ +ints = [1, 2, 3] +floats = [1.1, 2.1, 3.1] +strings = ["a", "b", "c"] +dates = [ + 1987-07-05T17:45:00Z, + 1979-05-27T07:32:00Z, + 2006-06-01T11:00:00Z, +] diff --git a/main.go b/main.go new file mode 100644 index 0000000..6846bf6 --- /dev/null +++ b/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "io/ioutil" + "os" + + "github.com/BurntSushi/toml" + "gopkg.in/alecthomas/kingpin.v2" +) + +var ( + inFile = kingpin.Arg("file", "TOML file.").Required().ExistingFile() + quiet = kingpin.Flag("quiet", "Don't output on success.").Short('q').Bool() +) + +func main() { + + // support -h for --help + kingpin.CommandLine.HelpFlag.Short('h') + kingpin.Parse() + + data, _ := ioutil.ReadFile(*inFile) + + var f interface{} + _, err := toml.Decode(string(data), &f) + if err != nil { + fmt.Println("ERROR:", *inFile, err) + os.Exit(1) + } + + if !*quiet { + fmt.Println("OK:", *inFile) + } +}