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
}
}
}
} }
} }
...@@ -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