-
-
Notifications
You must be signed in to change notification settings - Fork 522
/
main.go
46 lines (38 loc) · 871 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 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 any
if err := json.NewDecoder(os.Stdin).Decode(&tmp); err != nil {
log.Fatalf("Error decoding JSON: %s", err)
}
rm, err := tag.Remove(tmp)
if err != nil {
log.Fatalf("Error decoding JSON: %s", err)
}
if err := toml.NewEncoder(os.Stdout).Encode(rm); err != nil {
log.Fatalf("Error encoding TOML: %s", err)
}
}