use error groups so we can return errors
This commit is contained in:
parent
e6477d13fb
commit
8a7ec456f1
|
@ -2,9 +2,10 @@ package breakpoint
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/common"
|
"github.com/hashicorp/packer/common"
|
||||||
"github.com/hashicorp/packer/helper/config"
|
"github.com/hashicorp/packer/helper/config"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
@ -60,20 +61,22 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
||||||
message := fmt.Sprintf(
|
message := fmt.Sprintf(
|
||||||
"Press enter to continue.")
|
"Press enter to continue.")
|
||||||
|
|
||||||
|
var g errgroup.Group
|
||||||
result := make(chan string, 1)
|
result := make(chan string, 1)
|
||||||
go func() {
|
g.Go(func() error {
|
||||||
line, err := ui.Ask(message)
|
line, err := ui.Ask(message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error asking for input: %s", err)
|
return fmt.Errorf("Error asking for input: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
result <- line
|
result <- line
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-result:
|
|
||||||
return nil
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err := g.Wait(); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Cancel() {
|
func (p *Provisioner) Cancel() {
|
||||||
|
|
Loading…
Reference in New Issue