2013-03-24 14:03:53 -07:00
|
|
|
package packer
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
import "io"
|
|
|
|
|
|
|
|
// The Ui interface handles all communication for Packer with the outside
|
|
|
|
// world. This sort of control allows us to strictly control how output
|
|
|
|
// is formatted and various levels of output.
|
|
|
|
type Ui interface {
|
|
|
|
Say(format string, a ...interface{})
|
2013-05-10 17:01:24 -07:00
|
|
|
Error(format string, a ...interface{})
|
2013-03-24 14:03:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// The ReaderWriterUi is a UI that writes and reads from standard Go
|
|
|
|
// io.Reader and io.Writer.
|
|
|
|
type ReaderWriterUi struct {
|
|
|
|
Reader io.Reader
|
|
|
|
Writer io.Writer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rw *ReaderWriterUi) Say(format string, a ...interface{}) {
|
2013-05-08 17:09:10 -07:00
|
|
|
_, err := fmt.Fprintf(rw.Writer, format, a...)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2013-03-24 14:03:53 -07:00
|
|
|
}
|
2013-05-08 15:12:48 -07:00
|
|
|
|
|
|
|
func (rw *ReaderWriterUi) Error(format string, a ...interface{}) {
|
2013-05-08 17:09:10 -07:00
|
|
|
_, err := fmt.Fprintf(rw.Writer, format, a...)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2013-05-08 15:12:48 -07:00
|
|
|
}
|