From 8ab777d82234115d0015360bd7cc5ff0739eda10 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sun, 14 Jul 2019 19:52:14 -0700 Subject: [PATCH] improve powershell script generation --- shell/powershell/powershell.go | 8 ++++---- shell/powershell/powershell_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/shell/powershell/powershell.go b/shell/powershell/powershell.go index 51615c2..8192a4b 100644 --- a/shell/powershell/powershell.go +++ b/shell/powershell/powershell.go @@ -29,8 +29,8 @@ func Command() (string, []string) { func Script(commands []string) string { var buf bytes.Buffer for _, command := range commands { - escaped := fmt.Sprintf("%q", command) - escaped = strings.Replace(escaped, "$", `\$`, -1) + escaped := fmt.Sprintf("%q", "+ "+command) + escaped = strings.Replace(escaped, "$", "`$", -1) buf.WriteString(fmt.Sprintf( traceScript, escaped, @@ -53,6 +53,6 @@ $erroractionpreference = "stop" // traceScript is a helper script that is added to // the build script to trace a command. const traceScript = ` -Write-Output ('+ %s'); -& %s; if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE} +echo %s +%s ` diff --git a/shell/powershell/powershell_test.go b/shell/powershell/powershell_test.go index 0600891..e0038ce 100644 --- a/shell/powershell/powershell_test.go +++ b/shell/powershell/powershell_test.go @@ -39,10 +39,10 @@ func TestScript(t *testing.T) { var exampleScript = ` $erroractionpreference = "stop" -Write-Output ('+ "go build"'); -& go build; if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE} +echo "+ go build" +go build -Write-Output ('+ "go test"'); -& go test; if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE} +echo "+ go test" +go test `