From 95096d75980f944ff209420e5cbfbfd658694c96 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 9 Jul 2021 15:41:18 +1000 Subject: [PATCH] add a string check for errors in deploying to make sure proper exit codes are used --- cmd/deploy.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/cmd/deploy.go b/cmd/deploy.go index 79832e62..a5056030 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -3,6 +3,7 @@ package cmd import ( "context" "fmt" + "strings" "github.com/amazeeio/lagoon-cli/internal/lagoon" "github.com/amazeeio/lagoon-cli/internal/lagoon/client" @@ -53,7 +54,11 @@ use 'lagoon deploy latest' instead`, if err != nil { return err } - fmt.Println(result.DeployEnvironmentBranch) + response := result.DeployEnvironmentBranch + if strings.HasPrefix(response, "Error: ") { + return fmt.Errorf(strings.Trim(response, "Error: ")) + } + fmt.Println(response) } return nil }, @@ -99,7 +104,11 @@ var deployPromoteCmd = &cobra.Command{ if err != nil { return err } - fmt.Println(result.DeployEnvironmentPromote) + response := result.DeployEnvironmentPromote + if strings.HasPrefix(response, "Error: ") { + return fmt.Errorf(strings.Trim(response, "Error: ")) + } + fmt.Println(response) } return nil }, @@ -142,7 +151,11 @@ This environment should already exist in lagoon. It is analogous with the 'Deplo if err != nil { return err } - fmt.Println(result.DeployEnvironmentLatest) + response := result.DeployEnvironmentLatest + if strings.HasPrefix(response, "Error: ") { + return fmt.Errorf(strings.Trim(response, "Error: ")) + } + fmt.Println(response) } return nil }, @@ -214,7 +227,11 @@ This pullrequest may not already exist as an environment in lagoon.`, if err != nil { return err } - fmt.Println(result.DeployEnvironmentPullrequest) + response := result.DeployEnvironmentPullrequest + if strings.HasPrefix(response, "Error: ") { + return fmt.Errorf(strings.Trim(response, "Error: ")) + } + fmt.Println(response) } return nil },