initial commit
This commit is contained in:
commit
3dfe7ec69d
5 changed files with 89 additions and 0 deletions
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -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.
|
24
README.md
Normal file
24
README.md
Normal file
|
@ -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)
|
1
examples/invalid-key-open-bracket.toml
Normal file
1
examples/invalid-key-open-bracket.toml
Normal file
|
@ -0,0 +1 @@
|
|||
[abc = 1
|
8
examples/valid-arrays.toml
Normal file
8
examples/valid-arrays.toml
Normal file
|
@ -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,
|
||||
]
|
35
main.go
Normal file
35
main.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue