command: UIOutput is functinal

This commit is contained in:
Mitchell Hashimoto 2014-10-04 10:25:54 -07:00
parent 6d9463bfa8
commit b2342866c9
1 changed files with 13 additions and 0 deletions

View File

@ -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}
}