From 2282560e7a5091f6da8402d472b9b17e6491c58e Mon Sep 17 00:00:00 2001 From: mitch Date: Fri, 21 Oct 2022 09:39:06 -0400 Subject: [PATCH] Added exit code --- cmd/main.go | 7 ++++++- versionedTerraform.go | 14 -------------- versionedTerraform_test.go | 2 +- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 8f79c2f..da57d3c 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -110,5 +110,10 @@ func main() { Stdout: os.Stdout, Stderr: os.Stderr, } - cmd.Run() + err = cmd.Run() + if err != nil { + if exitError, ok := err.(*exec.ExitError); ok { + exitError.ExitCode() + } + } } diff --git a/versionedTerraform.go b/versionedTerraform.go index 398de32..5aaf8b5 100644 --- a/versionedTerraform.go +++ b/versionedTerraform.go @@ -13,15 +13,6 @@ import ( "strings" ) -func (*Version) latestMajorVersion() { -} - -func (*Version) latestMinorVersion() { -} - -func (*Version) latestPatchVersion() { -} - type Version struct { Version SemVersion availableVersions []SemVersion @@ -36,7 +27,6 @@ const ( //getLatestMajorRelease() returns the latest major release from Version func (v *Version) getLatestMajorRelease() { - //todo clean up for _, release := range v.availableVersions { if release.majorVersion == v.Version.majorVersion && release.minorVersion == v.Version.minorVersion && @@ -118,10 +108,6 @@ func (v *Version) InstallTerraformVersion() error { versionedFileName := homeDir + versionedTerraformFolder + "/" + terraformPrefix + v.Version.ToString() versionedFile, err := os.OpenFile(versionedFileName, os.O_WRONLY, 0755) if os.IsNotExist(err) { - //_, err = os.Create(versionedFileName) - //if err != nil { - // return err - //} versionedFile, err = os.OpenFile(versionedFileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) if err != nil { return err diff --git a/versionedTerraform_test.go b/versionedTerraform_test.go index cb1003b..66369bf 100644 --- a/versionedTerraform_test.go +++ b/versionedTerraform_test.go @@ -138,7 +138,7 @@ func TestIsVersionGreater(t *testing.T) { func TestGetVersionList(t *testing.T) { //todo write test for this - //response, _ := getVersionList() + //response, _ := GetVersionList() //for _, Version := range response { // t.Errorf("%v", Version) //}