From b2342866c9835485c667216b309b089da6d73ca0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 4 Oct 2014 10:25:54 -0700 Subject: [PATCH] command: UIOutput is functinal --- command/ui_output.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/command/ui_output.go b/command/ui_output.go index 7e8b574a3b..32cde2ef9f 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} }