Skip to content

Commit f046c12

Browse files
committed
--on-error=ask: wait for the user input
1 parent 523f1ce commit f046c12

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

multistep/commonsteps/multistep_runner.go

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ package commonsteps
66
import (
77
"context"
88
"fmt"
9-
"log"
10-
"reflect"
11-
"strings"
12-
"time"
13-
149
"github.com/hashicorp/packer-plugin-sdk/common"
1510
"github.com/hashicorp/packer-plugin-sdk/multistep"
1611
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
12+
"log"
13+
"reflect"
14+
"strings"
1715
)
1816

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

124-
switch ask(s.ui, typeName(s.step), state) {
122+
s.ui.Say(fmt.Sprintf("Step %q failed", typeName(s.step)))
123+
124+
switch askPrompt(s.ui) {
125125
case askCleanup:
126126
return
127127
case askAbort:
@@ -151,26 +151,6 @@ const (
151151
askRetry
152152
)
153153

154-
func ask(ui packersdk.Ui, name string, state multistep.StateBag) askResponse {
155-
ui.Say(fmt.Sprintf("Step %q failed", name))
156-
157-
result := make(chan askResponse)
158-
go func() {
159-
result <- askPrompt(ui)
160-
}()
161-
162-
for {
163-
select {
164-
case response := <-result:
165-
return response
166-
case <-time.After(100 * time.Millisecond):
167-
if _, ok := state.GetOk(multistep.StateCancelled); ok {
168-
return askCleanup
169-
}
170-
}
171-
}
172-
}
173-
174154
func askPrompt(ui packersdk.Ui) askResponse {
175155
for {
176156
line, err := ui.Ask("[c] Clean up and exit, [a] abort without cleanup, or [r] retry step (build may fail even if retry succeeds)?")

0 commit comments

Comments
 (0)