Skip to content

Commit 9a80667

Browse files
committed
Add -json flag to tomlv
1 parent 3203540 commit 9a80667

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cmd/tomlv/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package main
33

44
import (
5+
"encoding/json"
56
"flag"
67
"fmt"
78
"log"
@@ -16,13 +17,15 @@ import (
1617

1718
var (
1819
flagTypes = false
20+
flagJSON = false
1921
flagTime = false
2022
)
2123

2224
func init() {
2325
log.SetFlags(0)
2426
flag.BoolVar(&flagTypes, "types", flagTypes, "Show the types for every key.")
2527
flag.BoolVar(&flagTime, "time", flagTypes, "Show how long the parsing took.")
28+
flag.BoolVar(&flagJSON, "json", flagTypes, "Output parsed document as JSON.")
2629
flag.Usage = usage
2730
flag.Parse()
2831
}
@@ -50,6 +53,12 @@ func main() {
5053
if flagTypes {
5154
printTypes(md)
5255
}
56+
if flagJSON {
57+
enc := json.NewEncoder(os.Stdout)
58+
enc.SetEscapeHTML(false)
59+
enc.SetIndent("", " ")
60+
enc.Encode(tmp)
61+
}
5362
}
5463
}
5564

0 commit comments

Comments
 (0)