Enable multi ui to check for interactive uis

This commit is contained in:
sophia 2021-05-10 15:48:10 -05:00 committed by Paul Hinze
parent aff6edc31b
commit 9b3d07382a
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 19 additions and 2 deletions

View File

@ -273,7 +273,7 @@ func (p *Project) callDynamicFunc(
argmapper.Typed(
p.jobInfo,
p.dir,
terminal.ConsoleUI(ctx),
p.UI,
),
)

View File

@ -1,6 +1,7 @@
package runner
import (
"errors"
"io"
"github.com/hashicorp/vagrant-plugin-sdk/terminal"
@ -22,10 +23,26 @@ func (u *multiUI) Close() error {
}
func (u *multiUI) Input(input *terminal.Input) (string, error) {
return "", terminal.ErrNonInteractive
numInteractive := 0
var term terminal.UI
for _, u := range u.UIs {
if u.Interactive() {
numInteractive += 1
term = u
}
}
if numInteractive > 1 {
return "", errors.New("More than one interactive terminal available. Please ensure only one interactive terminal is available")
}
return term.Input(input)
}
func (u *multiUI) Interactive() bool {
for _, u := range u.UIs {
if u.Interactive() {
return true
}
}
return false
}