quartz/pkg/mod/github.com/!burnt!sushi/toml@v0.4.1/cmd/toml-test-encoder/main.go
Adam Gospodarczyk da2d93f602 Brain
2022-04-26 16:25:19 +02:00

42 lines
798 B
Go

// Command toml-test-encoder satisfies the toml-test interface for testing TOML
// encoders. Namely, it accepts JSON on stdin and outputs TOML on stdout.
package main
import (
"encoding/json"
"flag"
"log"
"os"
"path"
"github.com/BurntSushi/toml"
"github.com/BurntSushi/toml/internal/tag"
)
func init() {
log.SetFlags(0)
flag.Usage = usage
flag.Parse()
}
func usage() {
log.Printf("Usage: %s < json-file\n", path.Base(os.Args[0]))
flag.PrintDefaults()
os.Exit(1)
}
func main() {
if flag.NArg() != 0 {
flag.Usage()
}
var tmp interface{}
if err := json.NewDecoder(os.Stdin).Decode(&tmp); err != nil {
log.Fatalf("Error decoding JSON: %s", err)
}
if err := toml.NewEncoder(os.Stdout).Encode(tag.Remove(tmp)); err != nil {
log.Fatalf("Error encoding TOML: %s", err)
}
}