diff --git a/command/ui_output.go b/command/ui_output.go index 7e8b574a3..32cde2ef9 100644 --- a/command/ui_output.go +++ b/command/ui_output.go @@ -1,6 +1,8 @@ package command import ( + "sync" + "github.com/mitchellh/cli" "github.com/mitchellh/colorstring" ) @@ -9,7 +11,18 @@ import ( type UIOutput struct { Colorize *colorstring.Colorize Ui cli.Ui + + once sync.Once + ui cli.Ui } func (u *UIOutput) Output(v string) { + u.once.Do(u.init) + u.ui.Output(v) +} + +func (u *UIOutput) init() { + // Wrap the ui so that it is safe for concurrency regardless of the + // underlying reader/writer that is in place. + u.ui = &cli.ConcurrentUi{Ui: u.Ui} }