-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
150 lines (134 loc) · 3.27 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package main
import (
_ "embed" // required for embed
"fmt"
"os"
"sort"
"time"
"sato/src/arm"
"sato/src/cf"
"sato/src/see"
"sato/src/version"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
)
//goland:noinspection GoLinter
func main() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
var file string
var destination string
var resource string
var flip bool
app := &cli.App{
EnableBashCompletion: true,
Flags: []cli.Flag{},
Commands: []*cli.Command{
{
Name: "parse",
Usage: "translate CFN to Terraform",
Action: func(*cli.Context) error {
err := cf.Parse(file, destination)
if err != nil {
log.Info().Msgf(err.Error())
}
return nil
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "file",
Aliases: []string{"f"},
Usage: "Cloudformation file to parse",
Required: true,
Destination: &file,
},
&cli.StringFlag{
Name: "destination",
Aliases: []string{"d"},
Usage: "Destination to write Terraform",
Value: ".sato",
Destination: &destination,
},
},
},
{
Name: "version",
Aliases: []string{"v"},
Usage: "Outputs the application version",
UsageText: "sato version",
Action: func(*cli.Context) error {
//goland:noinspection GoLinter
fmt.Println(version.Version)
return nil
},
},
{
Name: "bisect",
Usage: "translate ARM to Terraform",
Action: func(*cli.Context) error {
err := arm.Parse(file, destination)
if err != nil {
log.Info().Msgf(err.Error())
}
return nil
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "file",
Aliases: []string{"f"},
Usage: "Arm file to parse",
Required: true,
Destination: &file,
},
&cli.StringFlag{
Name: "destination",
Aliases: []string{"d"},
Usage: "Destination to write Terraform",
Value: ".sato",
Destination: &destination,
},
},
},
{
Name: "see",
Usage: "shows equivalent Terraform resource or the reverse",
Action: func(*cli.Context) error {
result, err := see.Lookup(resource, flip)
if result == nil {
//goland:noinspection GoLinter
return fmt.Errorf("see failed with error %w", err)
}
fmt.Print(*result)
fmt.Print("\n")
return err
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "resource",
Aliases: []string{"r"},
Usage: "target resource for conversion",
Required: true,
Destination: &resource,
},
&cli.BoolFlag{
Name: "flip",
Aliases: []string{"f"},
Usage: "reverse the lookup",
Required: false,
Destination: &flip,
},
},
},
},
Name: "sato",
Usage: "Translate Cloudformation or ARM to Terraform",
Compiled: time.Time{},
Authors: []*cli.Author{{Name: "James Woolfenden", Email: "jim.wolf@duck.com"}},
Version: version.Version,
}
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
if err := app.Run(os.Args); err != nil {
log.Fatal().Err(err).Msg("Sato failure")
}
}