Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions multistep/commonsteps/multistep_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ package commonsteps
import (
"context"
"fmt"
"log"
"reflect"
"strings"
"time"

"github.com/hashicorp/packer-plugin-sdk/common"
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"log"
"reflect"
"strings"
)

func newRunner(steps []multistep.Step, config common.PackerConfig, ui packersdk.Ui) (multistep.Runner, multistep.DebugPauseFn) {
Expand Down Expand Up @@ -121,7 +119,9 @@ func (s askStep) Run(ctx context.Context, state multistep.StateBag) (action mult
s.ui.Error(fmt.Sprintf("%s", err))
}

switch ask(s.ui, typeName(s.step), state) {
s.ui.Say(fmt.Sprintf("Step %q failed", typeName(s.step)))

switch askPrompt(s.ui) {
case askCleanup:
return
case askAbort:
Expand Down Expand Up @@ -151,26 +151,6 @@ const (
askRetry
)

func ask(ui packersdk.Ui, name string, state multistep.StateBag) askResponse {
ui.Say(fmt.Sprintf("Step %q failed", name))

result := make(chan askResponse)
go func() {
result <- askPrompt(ui)
}()

for {
select {
case response := <-result:
return response
case <-time.After(100 * time.Millisecond):
if _, ok := state.GetOk(multistep.StateCancelled); ok {
return askCleanup
}
}
}
}

func askPrompt(ui packersdk.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)?")
Expand Down
Loading