-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
84 lines (74 loc) · 1.9 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
package main
import (
"fmt"
"os"
"github.com/chroju/tfcloud/commands"
"github.com/mitchellh/cli"
)
const (
app = "tfcloud"
version = "0.3.0"
)
var (
// UI is a cli.Ui
UI cli.Ui
// Format is a format of output
Format commands.Format
)
func init() {
UI = &cli.ColoredUi{
Ui: &cli.BasicUi{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stderr,
},
WarnColor: cli.UiColorYellow,
ErrorColor: cli.UiColorRed,
}
}
func main() {
format := commands.Format(os.Getenv("TFCLOUD_FORMAT"))
command := commands.Command{
UI: UI,
Format: format,
}
c := cli.NewCLI(app, version)
c.Args = os.Args[1:]
c.Commands = map[string]cli.CommandFactory{
"run": func() (cli.Command, error) {
return &commands.RunCommand{Command: command}, nil
},
"run list": func() (cli.Command, error) {
return &commands.RunListCommand{Command: command}, nil
},
"run apply": func() (cli.Command, error) {
return &commands.RunApplyCommand{Command: command}, nil
},
"workspace": func() (cli.Command, error) {
return &commands.WorkspaceCommand{Command: command}, nil
},
"workspace list": func() (cli.Command, error) {
return &commands.WorkspaceListCommand{Command: command}, nil
},
"workspace upgrade": func() (cli.Command, error) {
return &commands.WorkspaceUpgradeCommand{Command: command}, nil
},
"workspace view": func() (cli.Command, error) {
return &commands.WorkspaceViewCommand{Command: command}, nil
},
"module": func() (cli.Command, error) {
return &commands.ModuleCommand{Command: command}, nil
},
"module list": func() (cli.Command, error) {
return &commands.ModuleListCommand{Command: command}, nil
},
"module versions": func() (cli.Command, error) {
return &commands.ModuleVersionsCommand{Command: command}, nil
},
}
exitStatus, err := c.Run()
if err != nil {
UI.Error(fmt.Sprintf("Error: %s", err))
}
os.Exit(exitStatus)
}