Skip to content

Commit

Permalink
fix: use stringarray instead of stringslice for buildvars (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Apr 8, 2024
1 parent b21fbfd commit fba77eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
17 changes: 9 additions & 8 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"fmt"

"github.com/spf13/cobra"
"github.com/uselagoon/lagoon-cli/internal/lagoon"
"github.com/uselagoon/lagoon-cli/internal/lagoon/client"
Expand Down Expand Up @@ -46,7 +47,7 @@ use 'lagoon deploy latest' instead`,
return fmt.Errorf("Missing arguments: Project name or branch name is not defined")
}

buildVarStrings, err := cmd.Flags().GetStringSlice("buildvar")
buildVarStrings, err := cmd.Flags().GetStringArray("buildvar")
if err != nil {
return err
}
Expand Down Expand Up @@ -111,7 +112,7 @@ var deployPromoteCmd = &cobra.Command{
return fmt.Errorf("Missing arguments: Project name, source environment, or destination environment is not defined")
}

buildVarStrings, err := cmd.Flags().GetStringSlice("buildvar")
buildVarStrings, err := cmd.Flags().GetStringArray("buildvar")
if err != nil {
return err
}
Expand Down Expand Up @@ -165,7 +166,7 @@ This environment should already exist in lagoon. It is analogous with the 'Deplo
return err
}

buildVarStrings, err := cmd.Flags().GetStringSlice("buildvar")
buildVarStrings, err := cmd.Flags().GetStringArray("buildvar")
if err != nil {
return err
}
Expand Down Expand Up @@ -247,7 +248,7 @@ This pullrequest may not already exist as an environment in lagoon.`,
baseBranchRef == "" || headBranchName == "" || headBranchRef == "" {
return fmt.Errorf("Missing arguments: Project name, title, number, baseBranchName, baseBranchRef, headBranchName, or headBranchRef is not defined")
}
buildVarStrings, err := cmd.Flags().GetStringSlice("buildvar")
buildVarStrings, err := cmd.Flags().GetStringArray("buildvar")
if err != nil {
return err
}
Expand Down Expand Up @@ -304,17 +305,17 @@ func init() {

const returnDataUsageText = "Returns the build name instead of success text"
deployLatestCmd.Flags().Bool("returnData", false, returnDataUsageText)
deployLatestCmd.Flags().StringSlice("buildvar", []string{}, "Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])")
deployLatestCmd.Flags().StringArray("buildvar", []string{}, "Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])")

deployBranchCmd.Flags().StringP("branch", "b", "", "Branch name to deploy")
deployBranchCmd.Flags().StringP("branchRef", "r", "", "Branch ref to deploy")
deployBranchCmd.Flags().Bool("returnData", false, returnDataUsageText)
deployBranchCmd.Flags().StringSlice("buildvar", []string{}, "Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])")
deployBranchCmd.Flags().StringArray("buildvar", []string{}, "Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])")

deployPromoteCmd.Flags().StringP("destination", "d", "", "Destination environment name to create")
deployPromoteCmd.Flags().StringP("source", "s", "", "Source environment name to use as the base to deploy from")
deployPromoteCmd.Flags().Bool("returnData", false, returnDataUsageText)
deployPromoteCmd.Flags().StringSlice("buildvar", []string{}, "Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])")
deployPromoteCmd.Flags().StringArray("buildvar", []string{}, "Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])")

deployPullrequestCmd.Flags().StringP("title", "t", "", "Pullrequest title")
deployPullrequestCmd.Flags().UintP("number", "n", 0, "Pullrequest number")
Expand All @@ -323,5 +324,5 @@ func init() {
deployPullrequestCmd.Flags().StringP("headBranchName", "H", "", "Pullrequest head branch name")
deployPullrequestCmd.Flags().StringP("headBranchRef", "M", "", "Pullrequest head branch reference hash")
deployPullrequestCmd.Flags().Bool("returnData", false, returnDataUsageText)
deployPullrequestCmd.Flags().StringSlice("buildvar", []string{}, "Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])")
deployPullrequestCmd.Flags().StringArray("buildvar", []string{}, "Add one or more build variables to deployment (--buildvar KEY1=VALUE1 [--buildvar KEY2=VALUE2])")
}
18 changes: 17 additions & 1 deletion cmd/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cmd

import (
"github.com/uselagoon/lagoon-cli/internal/schema"
"reflect"
"testing"

"github.com/uselagoon/lagoon-cli/internal/schema"

"github.com/guregu/null"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -244,6 +245,21 @@ func Test_buildVarsToMap(t *testing.T) {
},
wantErr: false,
},
{
name: "Valid case - entry with comma separated items",
args: args{
slice: []string{
`KEY1=type:thistype,othertype:thisone`,
},
},
want: []schema.EnvKeyValueInput{
{
Name: "KEY1",
Value: "type:thistype,othertype:thisone",
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit fba77eb

Please sign in to comment.