-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (55 loc) · 991 Bytes
/
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
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() {
bin := os.Args[0]
args := []string{}
if len(os.Args) > 1 {
args = os.Args[1:]
}
if filepath.Base(bin) == "terraform" {
runTerraform(args, false)
os.Exit(0)
}
if err := NewApp().Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}
func runTerraform(args []string, verbose bool) {
k, err := NewConfiguration()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
c, err := readConstraint()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
tf, err := NewTerraform(k.BinaryStorePath, verbose)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if verbose {
fmt.Printf("Version constraint: %s\n", c.String())
}
latest, err := tf.FindLatest(c)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if verbose {
fmt.Printf("Version used: %s\n\n", latest.String())
}
s, err := tf.Run(latest, args, k.Wrapper)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(s.ExitCode())
}