Commit 21b6d2a4 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/common: multistep debug fn gracefully exits during an interrupt

parent ac029d9e
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"time"
) )
// MultistepDebugFn will return a proper multistep.DebugPauseFn to // MultistepDebugFn will return a proper multistep.DebugPauseFn to
...@@ -21,10 +22,23 @@ func MultistepDebugFn(ui packer.Ui) multistep.DebugPauseFn { ...@@ -21,10 +22,23 @@ func MultistepDebugFn(ui packer.Ui) multistep.DebugPauseFn {
} }
message := fmt.Sprintf( message := fmt.Sprintf(
"Pausing %s step '%s'. Press any key to continue.\n", "Pausing %s step '%s'. Press any key to continue.",
locationString, name) locationString, name)
ui.Say(message) result := make(chan string, 1)
ui.Ask("") go func() {
result <- ui.Ask(message)
}()
for {
select {
case <-result:
return
case <-time.After(100 * time.Millisecond):
if _, ok := state[multistep.StateCancelled]; ok {
return
}
}
}
} }
} }
...@@ -219,7 +219,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -219,7 +219,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Run! // Run!
if b.config.PackerDebug { if b.config.PackerDebug {
b.runner = &multistep.DebugRunner{ b.runner = &multistep.DebugRunner{
Steps: steps, Steps: steps,
PauseFn: common.MultistepDebugFn(ui), PauseFn: common.MultistepDebugFn(ui),
} }
} else { } else {
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
) )
type testUi struct { type testUi struct {
askCalled bool askCalled bool
askQuery string askQuery string
errorCalled bool errorCalled bool
errorMessage string errorMessage string
messageCalled bool messageCalled bool
......
...@@ -110,7 +110,7 @@ func (rw *ReaderWriterUi) Ask(query string) string { ...@@ -110,7 +110,7 @@ func (rw *ReaderWriterUi) Ask(query string) string {
var line string var line string
if _, err := fmt.Fscanln(rw.Reader, &line); err != nil { if _, err := fmt.Fscanln(rw.Reader, &line); err != nil {
panic(err) log.Printf("ui: scan err: %s", err)
} }
return line return line
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment