2013-03-24 17:03:53 -04:00
|
|
|
package packer
|
|
|
|
|
2013-05-21 02:43:37 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2013-05-21 14:40:07 -04:00
|
|
|
"log"
|
2013-05-21 02:43:37 -04:00
|
|
|
)
|
2013-03-24 17:03:53 -04:00
|
|
|
|
|
|
|
// 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 {
|
2013-05-27 18:12:48 -04:00
|
|
|
Say(string)
|
|
|
|
Error(string)
|
2013-03-24 17:03:53 -04:00
|
|
|
}
|
|
|
|
|
2013-05-21 16:20:51 -04:00
|
|
|
// PrefixedUi is a UI that wraps another UI implementation and adds a
|
|
|
|
// prefix to all the messages going out.
|
|
|
|
type PrefixedUi struct {
|
|
|
|
Prefix string
|
|
|
|
Ui Ui
|
|
|
|
}
|
|
|
|
|
2013-03-24 17:03:53 -04: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
|
|
|
|
}
|
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
func (u *PrefixedUi) Say(message string) {
|
|
|
|
u.Ui.Say(fmt.Sprintf("%s: %s", u.Prefix, message))
|
2013-05-21 16:20:51 -04:00
|
|
|
}
|
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
func (u *PrefixedUi) Error(message string) {
|
|
|
|
u.Ui.Error(fmt.Sprintf("%s: %s", u.Prefix, message))
|
2013-05-21 16:20:51 -04:00
|
|
|
}
|
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
func (rw *ReaderWriterUi) Say(message string) {
|
|
|
|
log.Printf("ui: %s", message)
|
|
|
|
_, err := fmt.Fprint(rw.Writer, message+"\n")
|
2013-05-08 20:09:10 -04:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2013-03-24 17:03:53 -04:00
|
|
|
}
|
2013-05-08 18:12:48 -04:00
|
|
|
|
2013-05-27 18:12:48 -04:00
|
|
|
func (rw *ReaderWriterUi) Error(message string) {
|
|
|
|
log.Printf("ui error: %s", message)
|
|
|
|
_, err := fmt.Fprint(rw.Writer, message+"\n")
|
2013-05-08 20:09:10 -04:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2013-05-08 18:12:48 -04:00
|
|
|
}
|