This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
forked from minamijoyo/tfmigrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (72 loc) · 1.57 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
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"
"github.com/hashicorp/logutils"
"github.com/minamijoyo/tfmigrate/command"
"github.com/mitchellh/cli"
)
// Version is a version number.
var version = "0.2.12"
func main() {
log.SetOutput(logOutput())
log.Printf("[DEBUG] [main] start: %s", strings.Join(os.Args, " "))
log.Printf("[DEBUG] [main] tfmigrate version: %s", version)
ui := &cli.BasicUi{
Writer: os.Stdout,
}
commands := initCommands(ui)
args := os.Args[1:]
c := &cli.CLI{
Name: "tfmigrate",
Version: version,
Args: args,
Commands: commands,
HelpWriter: os.Stdout,
}
exitStatus, err := c.Run()
if err != nil {
ui.Error(fmt.Sprintf("Failed to execute CLI: %s", err))
}
os.Exit(exitStatus)
}
func logOutput() io.Writer {
levels := []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"}
minLevel := os.Getenv("TFMIGRATE_LOG")
if len(minLevel) == 0 {
minLevel = "INFO" // default log level
}
// default log writer is null device.
writer := ioutil.Discard
if minLevel != "" {
writer = os.Stderr
}
filter := &logutils.LevelFilter{
Levels: levels,
MinLevel: logutils.LogLevel(minLevel),
Writer: writer,
}
return filter
}
func initCommands(ui cli.Ui) map[string]cli.CommandFactory {
meta := command.Meta{
UI: ui,
}
commands := map[string]cli.CommandFactory{
"plan": func() (cli.Command, error) {
return &command.PlanCommand{
Meta: meta,
}, nil
},
"apply": func() (cli.Command, error) {
return &command.ApplyCommand{
Meta: meta,
}, nil
},
}
return commands
}