Skip to content

Commit

Permalink
Add -time flag to tomlv
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed Oct 1, 2023
1 parent d17285a commit fb576ca
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/tomlv/main.go
Expand Up @@ -9,17 +9,20 @@ import (
"path"
"strings"
"text/tabwriter"
"time"

"github.com/BurntSushi/toml"
)

var (
flagTypes = 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.Usage = usage
flag.Parse()
}
Expand All @@ -36,10 +39,14 @@ func main() {
}
for _, f := range flag.Args() {
var tmp any
start := time.Now()
md, err := toml.DecodeFile(f, &tmp)
if err != nil {
log.Fatalf("Error in '%s': %s", f, err)
}
if flagTime {
fmt.Printf("%f\n", time.Now().Sub(start).Seconds())
}
if flagTypes {
printTypes(md)
}
Expand Down

0 comments on commit fb576ca

Please sign in to comment.