From 8abbfc2f760f47ca76e2ce59414804860fd09408 Mon Sep 17 00:00:00 2001 From: Jordi Monfar Date: Wed, 18 Dec 2024 17:15:30 +0100 Subject: [PATCH 1/2] Fix genTargetCmd function to deal with multiple and single selections Previous code only managed well single selection, multiple caused error modified: cmd/util.go --- cmd/util.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cmd/util.go b/cmd/util.go index 4ce4520..19bab37 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -102,11 +102,23 @@ func slice2String(slice []string) string { } func genTargetCmd(cmd *cobra.Command, action, target string) bytes.Buffer { - var buf bytes.Buffer - buf.WriteString("terraform " + action + " -target=" + target) - p, _ := cmd.Flags().GetInt("parallel") - buf.WriteString(fmt.Sprintf(" --parallelism=%d", p)) - return buf + var buf bytes.Buffer + buf.WriteString("terraform " + action) + target = strings.TrimSpace(target) + if strings.HasPrefix(target, "{") && strings.HasSuffix(target, "}") { + // Handle matrix of targets + target = strings.Trim(target, "{}") // Remove surrounding braces + targetList := strings.Split(target, ",") + for _, t := range targetList { + buf.WriteString(" -target=" + strings.TrimSpace(t)) + } + } else { + // Handle single target + buf.WriteString(" -target=" + target) + } + p, _ := cmd.Flags().GetInt("parallel") + buf.WriteString(fmt.Sprintf(" --parallelism=%d", p)) + return buf } func isYes(reader *bufio.Reader) bool { From 9945cd3445b2bf3bbb59014e8dc6d59e3a54a6a1 Mon Sep 17 00:00:00 2001 From: Jordi Monfar Date: Mon, 23 Dec 2024 13:52:53 +0100 Subject: [PATCH 2/2] Update cmd/util.go Co-authored-by: Takafumi Miyanaga --- cmd/util.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/util.go b/cmd/util.go index a330258..bad39db 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -105,7 +105,8 @@ func slice2String(slice []string) string { func genTargetCmd(cmd *cobra.Command, action, target string) bytes.Buffer { var buf bytes.Buffer - buf.WriteString("terraform " + action) + executable, _ := cmd.Flags().GetString("executable") + buf.WriteString(executable + " " + action) target = strings.TrimSpace(target) if strings.HasPrefix(target, "{") && strings.HasSuffix(target, "}") { // Handle matrix of targets