github.phpd.cn/hashicorp/packer@v1.3.2/common/multistep_debug.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "log" 6 "time" 7 8 "github.com/hashicorp/packer/helper/multistep" 9 "github.com/hashicorp/packer/packer" 10 ) 11 12 // MultistepDebugFn will return a proper multistep.DebugPauseFn to 13 // use for debugging if you're using multistep in your builder. 14 func MultistepDebugFn(ui packer.Ui) multistep.DebugPauseFn { 15 return func(loc multistep.DebugLocation, name string, state multistep.StateBag) { 16 var locationString string 17 switch loc { 18 case multistep.DebugLocationAfterRun: 19 locationString = "after run of" 20 case multistep.DebugLocationBeforeCleanup: 21 locationString = "before cleanup of" 22 default: 23 locationString = "at" 24 } 25 26 message := fmt.Sprintf( 27 "Pausing %s step '%s'. Press enter to continue.", 28 locationString, name) 29 30 result := make(chan string, 1) 31 go func() { 32 line, err := ui.Ask(message) 33 if err != nil { 34 log.Printf("Error asking for input: %s", err) 35 } 36 37 result <- line 38 }() 39 40 for { 41 select { 42 case <-result: 43 return 44 case <-time.After(100 * time.Millisecond): 45 if _, ok := state.GetOk(multistep.StateCancelled); ok { 46 return 47 } 48 } 49 } 50 } 51 }