diff --git a/packer/rpc/ui.go b/packer/rpc/ui.go index 6d69ca244..2a3807528 100644 --- a/packer/rpc/ui.go +++ b/packer/rpc/ui.go @@ -17,6 +17,12 @@ type UiServer struct { ui packer.Ui } +// The arguments sent to Ui.Machine +type UiMachineArgs struct { + category string + args []string +} + func (u *Ui) Ask(query string) (result string, err error) { err = u.client.Call("Ui.Ask", query, &result) return @@ -28,6 +34,17 @@ func (u *Ui) Error(message string) { } } +func (u *Ui) Machine(t string, args ...string) { + rpcArgs := &UiMachineArgs{ + category: t, + args: args, + } + + if err := u.client.Call("Ui.Message", rpcArgs, new(interface{})); err != nil { + panic(err) + } +} + func (u *Ui) Message(message string) { if err := u.client.Call("Ui.Message", message, new(interface{})); err != nil { panic(err) @@ -52,6 +69,13 @@ func (u *UiServer) Error(message *string, reply *interface{}) error { return nil } +func (u *UiServer) Machine(args *UiMachineArgs, reply *interface{}) error { + u.ui.Machine(args.category, args.args...) + + *reply = nil + return nil +} + func (u *UiServer) Message(message *string, reply *interface{}) error { u.ui.Message(*message) *reply = nil diff --git a/packer/rpc/ui_test.go b/packer/rpc/ui_test.go index 78c203540..7dae40763 100644 --- a/packer/rpc/ui_test.go +++ b/packer/rpc/ui_test.go @@ -11,6 +11,9 @@ type testUi struct { askQuery string errorCalled bool errorMessage string + machineCalled bool + machineType string + machineArgs []string messageCalled bool messageMessage string sayCalled bool @@ -28,6 +31,12 @@ func (u *testUi) Error(message string) { u.errorMessage = message } +func (u *testUi) Machine(t string, args ...string) { + u.machineCalled = true + u.machineType = t + u.machineArgs = args +} + func (u *testUi) Message(message string) { u.messageCalled = true u.messageMessage = message diff --git a/packer/ui.go b/packer/ui.go index f19ebc04b..5d5ca1065 100644 --- a/packer/ui.go +++ b/packer/ui.go @@ -33,6 +33,7 @@ type Ui interface { Say(string) Message(string) Error(string) + Machine(string, ...string) } // ColoredUi is a UI that is colored using terminal colors. @@ -80,6 +81,11 @@ func (u *ColoredUi) Error(message string) { u.Ui.Error(u.colorize(message, color, true)) } +func (u *ColoredUi) Machine(t string, args ...string) { + // Don't colorize machine-readable output + u.Ui.Machine(t, args...) +} + func (u *ColoredUi) colorize(message string, color UiColor, bold bool) string { if !u.supportsColors() { return message @@ -123,6 +129,11 @@ func (u *PrefixedUi) Error(message string) { u.Ui.Error(u.prefixLines(u.SayPrefix, message)) } +func (u *PrefixedUi) Machine(t string, args ...string) { + // Just pass it through for now. + u.Ui.Machine(t, args...) +} + func (u *PrefixedUi) prefixLines(prefix, message string) string { var result bytes.Buffer @@ -209,3 +220,7 @@ func (rw *ReaderWriterUi) Error(message string) { panic(err) } } + +func (rw *ReaderWriterUi) Machine(t string, args ...string) { + // TODO +} diff --git a/provisioner/file/provisioner_test.go b/provisioner/file/provisioner_test.go index 9c57ac452..c35f67cdb 100644 --- a/provisioner/file/provisioner_test.go +++ b/provisioner/file/provisioner_test.go @@ -106,6 +106,9 @@ func (su *stubUi) Ask(string) (string, error) { func (su *stubUi) Error(string) { } +func (su *stubUi) Machine(string, ...string) { +} + func (su *stubUi) Message(string) { }