diff --git a/mage_helpers/cdk.go b/mage_helpers/cdk.go index c99fb7a1d2d5fddd4470b3c399f5d97d79e0adb6..ca247d60be85213a31a085ff3957a17f003a333d 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 58ac652b6c15778f4250f47d8832158fde350c28..d7eac4d38bde5cd790895597bbcdb34dd1420026 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 ad03605a4fece2a5f7d5a782f6b8a760fb83f642..ef7573afa245bd797dac738e38bf3df3dec3d4c7 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 +}