Skip to content

Commit

Permalink
Add -json flag to tomlv
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed May 10, 2024
1 parent 3203540 commit 9a80667
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/tomlv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"log"
Expand All @@ -16,13 +17,15 @@ import (

var (
flagTypes = false
flagJSON = false
flagTime = false
)

func init() {
log.SetFlags(0)
flag.BoolVar(&flagTypes, "types", flagTypes, "Show the types for every key.")
flag.BoolVar(&flagTime, "time", flagTypes, "Show how long the parsing took.")
flag.BoolVar(&flagJSON, "json", flagTypes, "Output parsed document as JSON.")
flag.Usage = usage
flag.Parse()
}
Expand Down Expand Up @@ -50,6 +53,12 @@ func main() {
if flagTypes {
printTypes(md)
}
if flagJSON {
enc := json.NewEncoder(os.Stdout)
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
enc.Encode(tmp)
}
}
}

Expand Down

0 comments on commit 9a80667

Please sign in to comment.