packer-cn/common/multistep_debug.go

51 lines
1.1 KiB
Go
Raw Normal View History

2013-06-14 18:24:53 -04:00
package common
import (
"fmt"
2017-04-04 16:39:01 -04:00
"github.com/hashicorp/packer/packer"
2013-06-14 18:24:53 -04:00
"github.com/mitchellh/multistep"
"log"
"time"
2013-06-14 18:24:53 -04:00
)
// MultistepDebugFn will return a proper multistep.DebugPauseFn to
// use for debugging if you're using multistep in your builder.
func MultistepDebugFn(ui packer.Ui) multistep.DebugPauseFn {
2013-08-31 15:17:59 -04:00
return func(loc multistep.DebugLocation, name string, state multistep.StateBag) {
2013-06-14 18:24:53 -04:00
var locationString string
switch loc {
case multistep.DebugLocationAfterRun:
locationString = "after run of"
case multistep.DebugLocationBeforeCleanup:
locationString = "before cleanup of"
default:
locationString = "at"
}
message := fmt.Sprintf(
2014-03-13 00:40:27 -04:00
"Pausing %s step '%s'. Press enter to continue.",
2013-06-14 18:24:53 -04:00
locationString, name)
result := make(chan string, 1)
go func() {
line, err := ui.Ask(message)
if err != nil {
log.Printf("Error asking for input: %s", err)
}
result <- line
}()
for {
select {
case <-result:
return
case <-time.After(100 * time.Millisecond):
2013-08-31 15:17:59 -04:00
if _, ok := state.GetOk(multistep.StateCancelled); ok {
return
}
}
}
2013-06-14 18:24:53 -04:00
}
}