...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package main
19
20 import (
21 "io"
22
23 "github.com/pelletier/go-toml/v2"
24 "github.com/pelletier/go-toml/v2/internal/cli"
25 )
26
27 const usage = `tomll can be used in two ways:
28
29 Reading from stdin, writing to stdout:
30 cat file.toml | tomll > file.toml
31
32 Reading and updating a list of files in place:
33 tomll a.toml b.toml c.toml
34
35 When given a list of files, tomll will modify all files in place without asking.
36 `
37
38 func main() {
39 p := cli.Program{
40 Usage: usage,
41 Fn: convert,
42 Inplace: true,
43 }
44 p.Execute()
45 }
46
47 func convert(r io.Reader, w io.Writer) error {
48 var v interface{}
49
50 d := toml.NewDecoder(r)
51 err := d.Decode(&v)
52 if err != nil {
53 return err
54 }
55
56 e := toml.NewEncoder(w)
57 return e.Encode(v)
58 }
59
View as plain text