git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/toml/cmd/toml-test-encoder/main.go (about) 1 // Command toml-test-encoder satisfies the toml-test interface for testing TOML 2 // encoders. Namely, it accepts JSON on stdin and outputs TOML on stdout. 3 package main 4 5 import ( 6 "encoding/json" 7 "flag" 8 "log" 9 "os" 10 "path" 11 12 "git.sr.ht/~pingoo/stdx/toml" 13 "git.sr.ht/~pingoo/stdx/toml/internal/tag" 14 ) 15 16 func init() { 17 log.SetFlags(0) 18 flag.Usage = usage 19 flag.Parse() 20 } 21 22 func usage() { 23 log.Printf("Usage: %s < json-file\n", path.Base(os.Args[0])) 24 flag.PrintDefaults() 25 os.Exit(1) 26 } 27 28 func main() { 29 if flag.NArg() != 0 { 30 flag.Usage() 31 } 32 33 var tmp interface{} 34 if err := json.NewDecoder(os.Stdin).Decode(&tmp); err != nil { 35 log.Fatalf("Error decoding JSON: %s", err) 36 } 37 38 rm, err := tag.Remove(tmp) 39 if err != nil { 40 log.Fatalf("Error decoding JSON: %s", err) 41 } 42 43 if err := toml.NewEncoder(os.Stdout).Encode(rm); err != nil { 44 log.Fatalf("Error encoding TOML: %s", err) 45 } 46 }