Skip to content

Commit

Permalink
Allow upper case input to -on-error=ask
Browse files Browse the repository at this point in the history
  • Loading branch information
orivej committed Sep 16, 2016
1 parent e68c130 commit 55e51f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions common/multistep_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"reflect"
"strings"
"time"

"github.com/mitchellh/multistep"
Expand All @@ -13,7 +14,7 @@ import (

func newRunner(steps []multistep.Step, config PackerConfig, ui packer.Ui) (multistep.Runner, multistep.DebugPauseFn) {
switch config.PackerOnError {
case "cleanup", "":
case "cleanup":
case "abort":
for i, step := range steps {
steps[i] = abortStep{step, ui}
Expand All @@ -23,7 +24,7 @@ func newRunner(steps []multistep.Step, config PackerConfig, ui packer.Ui) (multi
steps[i] = askStep{step, ui}
}
default:
ui.Error(fmt.Sprintf("Ignoring unknown on-error value %q", config.PackerOnError))
ui.Error(fmt.Sprintf("Ignoring -on-error=%q argument: unknown on-error value", config.PackerOnError))
}

if config.PackerDebug {
Expand Down Expand Up @@ -145,17 +146,18 @@ func ask(ui packer.Ui, name string, state multistep.StateBag) askResponse {

func askPrompt(ui packer.Ui) askResponse {
for {
line, err := ui.Ask("[C]lean up and exit, [A]bort without cleanup, or [R]etry step (build may fail even if retry succeeds)? [car]")
line, err := ui.Ask("[C]lean up and exit, [a]bort without cleanup, or [r]etry step (build may fail even if retry succeeds)?")
if err != nil {
log.Printf("Error asking for input: %s", err)
}

switch {
case len(line) == 0 || line[0] == 'c':
input := strings.ToLower(line) + "c"
switch input[0] {
case 'c':
return askCleanup
case line[0] == 'a':
case 'a':
return askAbort
case line[0] == 'r':
case 'r':
return askRetry
}
ui.Say(fmt.Sprintf("Incorrect input: %#v", line))
Expand Down
2 changes: 1 addition & 1 deletion packer/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type Build interface {
// deleted prior to the build.
SetForce(bool)

// SetOnError will determines what to do when a normal multistep step fails
// SetOnError will determine what to do when a normal multistep step fails
// - "cleanup" - run cleanup steps
// - "abort" - exit without cleanup
// - "ask" - ask the user
Expand Down

0 comments on commit 55e51f5

Please sign in to comment.