improve powershell script generation

pull/1/head
Brad Rydzewski 5 years ago
parent 833e424937
commit 8ab777d822

@ -29,8 +29,8 @@ func Command() (string, []string) {
func Script(commands []string) string { func Script(commands []string) string {
var buf bytes.Buffer var buf bytes.Buffer
for _, command := range commands { for _, command := range commands {
escaped := fmt.Sprintf("%q", command) escaped := fmt.Sprintf("%q", "+ "+command)
escaped = strings.Replace(escaped, "$", `\$`, -1) escaped = strings.Replace(escaped, "$", "`$", -1)
buf.WriteString(fmt.Sprintf( buf.WriteString(fmt.Sprintf(
traceScript, traceScript,
escaped, escaped,
@ -53,6 +53,6 @@ $erroractionpreference = "stop"
// traceScript is a helper script that is added to // traceScript is a helper script that is added to
// the build script to trace a command. // the build script to trace a command.
const traceScript = ` const traceScript = `
Write-Output ('+ %s'); echo %s
& %s; if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE} %s
` `

@ -39,10 +39,10 @@ func TestScript(t *testing.T) {
var exampleScript = ` var exampleScript = `
$erroractionpreference = "stop" $erroractionpreference = "stop"
Write-Output ('+ "go build"'); echo "+ go build"
& go build; if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE} go build
Write-Output ('+ "go test"'); echo "+ go test"
& go test; if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE} go test
` `

Loading…
Cancel
Save