From 4288f330f79261cddfd73eb4834aa37bc219585f Mon Sep 17 00:00:00 2001
From: Johan de Klerk <jdeklerk00@gmail.com>
Date: Wed, 20 Oct 2021 09:34:51 +0200
Subject: [PATCH] Added logs

---
 mage_helpers/cdk.go         | 18 +++++-------------
 mage_helpers/debug.go       |  1 +
 mage_helpers/file_system.go |  9 +++++++++
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/mage_helpers/cdk.go b/mage_helpers/cdk.go
index c99fb7a..ca247d6 100644
--- a/mage_helpers/cdk.go
+++ b/mage_helpers/cdk.go
@@ -3,13 +3,11 @@ package mage_helpers
 import (
 	_ "embed"
 	"fmt"
+	"gopkg.in/yaml.v2"
 	"io/ioutil"
 	"os"
 	"os/exec"
 	"strconv"
-	"strings"
-
-	"gopkg.in/yaml.v2"
 )
 
 func CDKCompileTypeScript(cdkDir string) error {
@@ -50,8 +48,7 @@ func CDKDiff(cdkDir string, env string, stack string, local bool, profile string
 		`--exclusively=true`,
 		`--progress=events`)
 
-	fmt.Println(fmt.Sprintf("Running command: cdk %s", strings.Join(commandArgs, " ")))
-	cmd := exec.Command("cdk", commandArgs...)
+	cmd := BuildCommand("cdk", commandArgs)
 	cmd.Dir = cdkDir
 
 	output, err := cmd.CombinedOutput()
@@ -90,9 +87,7 @@ func CDKDeploy(cdkDir string, env string, stack string, exclusively bool, local
 		`--progress=events`,
 		`--app=./cdk.out`)
 
-	fmt.Println(fmt.Sprintf("Running command: cdk %s", strings.Join(commandArgs, " ")))
-
-	cmd := exec.Command("cdk", commandArgs...)
+	cmd := BuildCommand("cdk", commandArgs)
 	cmd.Dir = cdkDir
 
 	output, err := cmd.CombinedOutput()
@@ -123,8 +118,7 @@ func CDKSynthAll(cdkDir string, env string, profile string, local bool) error {
 	commandArgs = append(commandArgs,
 		`--progress=events`)
 
-	fmt.Println(fmt.Sprintf("Running command: cdk %s", strings.Join(commandArgs, " ")))
-	cmd := exec.Command("cdk", commandArgs...)
+	cmd := BuildCommand("cdk", commandArgs)
 	cmd.Dir = cdkDir
 
 	output, err := cmd.CombinedOutput()
@@ -176,9 +170,7 @@ func CDKSynthDebug(cdkDir string, env string, handler string, appName string, pr
 		`--no-staging`,
 	}
 
-	fmt.Println(fmt.Sprintf("Running command: cdk %s", strings.Join(commandArgs, " ")))
-
-	cmd := exec.Command("cdk", commandArgs...)
+	cmd := BuildCommand("cdk", commandArgs)
 	cmd.Dir = cdkDir
 
 	output, err := cmd.CombinedOutput()
diff --git a/mage_helpers/debug.go b/mage_helpers/debug.go
index 58ac652..d7eac4d 100644
--- a/mage_helpers/debug.go
+++ b/mage_helpers/debug.go
@@ -86,6 +86,7 @@ func runLongRunningSubProcess(ctx context.Context, name string, arg ...string) e
 		cancel()
 	}()
 
+	fmt.Println(fmt.Sprintf("Running command: %s %s", name, strings.Join(arg, " ")))
 	cmd := exec.CommandContext(cancelContext, name, arg...)
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stderr
diff --git a/mage_helpers/file_system.go b/mage_helpers/file_system.go
index ad03605..ef7573a 100644
--- a/mage_helpers/file_system.go
+++ b/mage_helpers/file_system.go
@@ -2,13 +2,16 @@ package mage_helpers
 
 import (
 	"context"
+	"fmt"
 	"io"
 	"io/ioutil"
 	"log"
 	"os"
+	"os/exec"
 	"os/signal"
 	"path"
 	"path/filepath"
+	"strings"
 
 	"github.com/thoas/go-funk"
 
@@ -168,3 +171,9 @@ func killWithContext(ctx context.Context) {
 		os.Exit(exitCodeInterrupt)
 	}()
 }
+
+func BuildCommand(command string, args []string) *exec.Cmd {
+	fmt.Println(fmt.Sprintf("Running command: %s %s", command, strings.Join(args, " ")))
+	cmd := exec.Command(command, args...)
+	return cmd
+}
-- 
GitLab