forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
52 lines (43 loc) · 1.02 KB
/
ui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package ui
import (
"fmt"
"io"
bosherr "github.com/cloudfoundry/bosh-agent/errors"
boshlog "github.com/cloudfoundry/bosh-agent/logger"
)
type UI interface {
Say(string)
Sayln(string)
Error(string)
}
type ui struct {
stdOut io.Writer
stdErr io.Writer
logger boshlog.Logger
}
const logTag = "ui"
func NewUI(stdOut, stdErr io.Writer, logger boshlog.Logger) UI {
return &ui{
stdOut: stdOut,
stdErr: stdErr,
logger: logger,
}
}
func (u *ui) Say(message string) {
_, err := fmt.Fprint(u.stdOut, message)
if err != nil {
u.logger.Error(logTag, bosherr.WrapError(err, "Writing to STDOUT: %s", message).Error())
}
}
func (u *ui) Sayln(message string) {
_, err := fmt.Fprintln(u.stdOut, message)
if err != nil {
u.logger.Error(logTag, bosherr.WrapError(err, "Writing to STDOUT (with newline): %s", message).Error())
}
}
func (u *ui) Error(message string) {
_, err := fmt.Fprintln(u.stdErr, message)
if err != nil {
u.logger.Error(logTag, bosherr.WrapError(err, "Writing to STDERR: %s", message).Error())
}
}