-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
77 lines (56 loc) · 1.73 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"flag"
"fmt"
"os"
)
const usage = `usage:
refmt [-t type] INPUT_FILE|"-" OUTPUT_FILE|"-"
Converts from one encoding to another. Supported formats (and their file extensions):
- HCL (.hcl or .tf)
- JSON (.json)
- YAML (.yaml or .yml)
If INPUT_FILE's extension is not recognized or INPUT_FILE is "-" (stdin),
refmt will try to guess input format.
If OUTPUT_FILE is "-" (stdout), destination format type is required to be
passed with -t flag.
refmt [-t type] merge ORIGINAL_FILE|"-" MIXIN_FILE|"-" OUTPUT_FILE|"-"
Merges the object defined in ORIGINAL_FILE with the object from MIXIN_FILE, writing
the resulting object to the OUTPUT_FILE.
The ORIGINAL_FILE, MIXIN_FILE and OUTPUT_FILE can have different encodings.
If ORIGINAL_FILE's extension is not recognized or ORIGINAL_FILE is "-" (stdin),
refmt will try to guess original format.
If ORIGINAL_FILE does not exist or is empty, refmt is going to use empty
object instead.
If MIXIN_FILE's extension is not recognized or MIXIN_FILE is "-" (stdin),
refmt will try to guess mixin format.
If OUTPUT_FILE is "-" (stdout), destination format type is required to be
passed with -t flag.
refmt [-t type] set INPUT_FILE key value
`
func die(v ...interface{}) {
fmt.Fprintln(os.Stderr, v...)
os.Exit(1)
}
func main() {
flag.Parse()
if flag.NArg() != 1 && flag.NArg() != 2 && flag.NArg() != 4 {
die(usage)
}
var err error
switch flag.Arg(0) {
case "set":
err = Set(flag.Arg(1), flag.Arg(2), flag.Arg(3))
case "merge":
err = Merge(flag.Arg(1), flag.Arg(2), flag.Arg(3))
case "dsn":
err = DSN(flag.Arg(1))
case "template":
err = Template(flag.Arg(1), flag.Arg(2), flag.Arg(3))
default:
err = Refmt(flag.Arg(0), flag.Arg(1))
}
if err != nil {
die(err)
}
}