Example #1
0
func askPrompt(ui packer.Ui) askResponse {
	for {
		line, err := ui.Ask("[c] Clean up and exit, [a] abort without cleanup, or [r] retry step (build may fail even if retry succeeds)?")
		if err != nil {
			log.Printf("Error asking for input: %s", err)
		}

		input := strings.ToLower(line) + "c"
		switch input[0] {
		case 'c':
			return askCleanup
		case 'a':
			return askAbort
		case 'r':
			return askRetry
		}
		ui.Say(fmt.Sprintf("Incorrect input: %#v", line))
	}
}
Example #2
0
// 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 {
	return func(loc multistep.DebugLocation, name string, state multistep.StateBag) {
		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(
			"Pausing %s step '%s'. Press enter to continue.",
			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):
				if _, ok := state.GetOk(multistep.StateCancelled); ok {
					return
				}
			}
		}
	}
}