-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathmain.go
79 lines (72 loc) · 3.54 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
package main
/*
* Version 0.12.0
* Compatible with Mac OS X AND other LINUX OS ONLY
*/
/*** OPERATION WORKFLOW ***/
/*
* 1- Create /usr/local/terraform directory if it does not exist
* 2- Download zip file from url to /usr/local/terraform
* 3- Unzip the file to /usr/local/terraform
* 4- Rename the file from `terraform` to `terraform_version`
* 5- Remove the downloaded zip file
* 6- Read the existing symlink for terraform (Check if it's a homebrew symlink)
* 7- Remove that symlink (Check if it's a homebrew symlink)
* 8- Create new symlink to binary `terraform_version`
*/
import (
"fmt"
"os"
lib "github.com/warrensbox/terraform-switcher/lib"
"github.com/warrensbox/terraform-switcher/lib/param_parsing"
)
var parameters = param_parsing.GetParameters()
var logger = lib.InitLogger(parameters.LogLevel)
var version string
func main() {
var err error = nil
switch {
case parameters.VersionFlag:
if version != "" {
fmt.Printf("Version: %s\n", version)
} else {
fmt.Println("Version not defined during build.")
}
os.Exit(0)
case parameters.HelpFlag:
lib.UsageMessage()
os.Exit(0)
case parameters.ListAllFlag:
/* show all terraform version including betas and RCs*/
err = lib.InstallProductOption(parameters.ProductEntity, true, parameters.DryRun, parameters.CustomBinaryPath, parameters.InstallPath, parameters.MirrorURL)
case parameters.LatestPre != "":
/* latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest) */
err = lib.InstallLatestProductImplicitVersion(parameters.ProductEntity, parameters.DryRun, parameters.LatestPre, parameters.CustomBinaryPath, parameters.InstallPath, parameters.MirrorURL, true)
case parameters.ShowLatestPre != "":
/* show latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest) */
lib.ShowLatestImplicitVersion(parameters.ShowLatestPre, parameters.MirrorURL, true)
case parameters.LatestStable != "":
/* latest implicit version. Ex: tfswitch --latest-stable 0.13 downloads 0.13.5 (latest) */
err = lib.InstallLatestProductImplicitVersion(parameters.ProductEntity, parameters.DryRun, parameters.LatestStable, parameters.CustomBinaryPath, parameters.InstallPath, parameters.MirrorURL, false)
case parameters.ShowLatestStable != "":
/* show latest implicit stable version. Ex: tfswitch --show-latest-stable 0.13 downloads 0.13.5 (latest) */
lib.ShowLatestImplicitVersion(parameters.ShowLatestStable, parameters.MirrorURL, false)
case parameters.LatestFlag:
/* latest stable version */
err = lib.InstallLatestProductVersion(parameters.ProductEntity, parameters.DryRun, parameters.CustomBinaryPath, parameters.InstallPath, parameters.MirrorURL)
case parameters.ShowLatestFlag:
/* show latest stable version */
lib.ShowLatestVersion(parameters.MirrorURL)
case parameters.Version != "":
err = lib.InstallProductVersion(parameters.ProductEntity, parameters.DryRun, parameters.Version, parameters.CustomBinaryPath, parameters.InstallPath, parameters.MirrorURL)
case parameters.DefaultVersion != "":
/* if default version is provided - Pick this instead of going for prompt */
err = lib.InstallProductVersion(parameters.ProductEntity, parameters.DryRun, parameters.DefaultVersion, parameters.CustomBinaryPath, parameters.InstallPath, parameters.MirrorURL)
default:
// Set list all false - only official release will be displayed
err = lib.InstallProductOption(parameters.ProductEntity, false, parameters.DryRun, parameters.CustomBinaryPath, parameters.InstallPath, parameters.MirrorURL)
}
if err != nil {
logger.Fatal(err)
}
}