builder/common: multistep debug fn gracefully exits during an interrupt
This commit is contained in:
parent
ac029d9ed0
commit
21b6d2a435
|
@ -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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue