Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
edab952a
Commit
edab952a
authored
Jun 03, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Add Message method to Ui
parent
37937c12
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
9 deletions
+49
-9
command/build/command.go
command/build/command.go
+1
-0
packer/rpc/ui.go
packer/rpc/ui.go
+12
-0
packer/rpc/ui_test.go
packer/rpc/ui_test.go
+14
-4
packer/ui.go
packer/ui.go
+18
-4
packer/ui_test.go
packer/ui_test.go
+4
-1
No files found.
command/build/command.go
View file @
edab952a
...
@@ -63,6 +63,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
...
@@ -63,6 +63,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
for
_
,
b
:=
range
builds
{
for
_
,
b
:=
range
builds
{
buildUis
[
b
.
Name
()]
=
&
packer
.
PrefixedUi
{
buildUis
[
b
.
Name
()]
=
&
packer
.
PrefixedUi
{
fmt
.
Sprintf
(
"==> %s"
,
b
.
Name
()),
fmt
.
Sprintf
(
"==> %s"
,
b
.
Name
()),
fmt
.
Sprintf
(
"--> %s"
,
b
.
Name
()),
env
.
Ui
(),
env
.
Ui
(),
}
}
}
}
...
...
packer/rpc/ui.go
View file @
edab952a
...
@@ -23,6 +23,12 @@ func (u *Ui) Error(message string) {
...
@@ -23,6 +23,12 @@ func (u *Ui) Error(message string) {
}
}
}
}
func
(
u
*
Ui
)
Message
(
message
string
)
{
if
err
:=
u
.
client
.
Call
(
"Ui.Message"
,
message
,
new
(
interface
{}));
err
!=
nil
{
panic
(
err
)
}
}
func
(
u
*
Ui
)
Say
(
message
string
)
{
func
(
u
*
Ui
)
Say
(
message
string
)
{
if
err
:=
u
.
client
.
Call
(
"Ui.Say"
,
message
,
new
(
interface
{}));
err
!=
nil
{
if
err
:=
u
.
client
.
Call
(
"Ui.Say"
,
message
,
new
(
interface
{}));
err
!=
nil
{
panic
(
err
)
panic
(
err
)
...
@@ -36,6 +42,12 @@ func (u *UiServer) Error(message *string, reply *interface{}) error {
...
@@ -36,6 +42,12 @@ func (u *UiServer) Error(message *string, reply *interface{}) error {
return
nil
return
nil
}
}
func
(
u
*
UiServer
)
Message
(
message
*
string
,
reply
*
interface
{})
error
{
u
.
ui
.
Message
(
*
message
)
*
reply
=
nil
return
nil
}
func
(
u
*
UiServer
)
Say
(
message
*
string
,
reply
*
interface
{})
error
{
func
(
u
*
UiServer
)
Say
(
message
*
string
,
reply
*
interface
{})
error
{
u
.
ui
.
Say
(
*
message
)
u
.
ui
.
Say
(
*
message
)
...
...
packer/rpc/ui_test.go
View file @
edab952a
...
@@ -7,10 +7,12 @@ import (
...
@@ -7,10 +7,12 @@ import (
)
)
type
testUi
struct
{
type
testUi
struct
{
errorCalled
bool
errorCalled
bool
errorMessage
string
errorMessage
string
sayCalled
bool
messageCalled
bool
sayMessage
string
messageMessage
string
sayCalled
bool
sayMessage
string
}
}
func
(
u
*
testUi
)
Error
(
message
string
)
{
func
(
u
*
testUi
)
Error
(
message
string
)
{
...
@@ -18,6 +20,11 @@ func (u *testUi) Error(message string) {
...
@@ -18,6 +20,11 @@ func (u *testUi) Error(message string) {
u
.
errorMessage
=
message
u
.
errorMessage
=
message
}
}
func
(
u
*
testUi
)
Message
(
message
string
)
{
u
.
messageCalled
=
true
u
.
messageMessage
=
message
}
func
(
u
*
testUi
)
Say
(
message
string
)
{
func
(
u
*
testUi
)
Say
(
message
string
)
{
u
.
sayCalled
=
true
u
.
sayCalled
=
true
u
.
sayMessage
=
message
u
.
sayMessage
=
message
...
@@ -46,6 +53,9 @@ func TestUiRPC(t *testing.T) {
...
@@ -46,6 +53,9 @@ func TestUiRPC(t *testing.T) {
uiClient
.
Error
(
"message"
)
uiClient
.
Error
(
"message"
)
assert
.
Equal
(
ui
.
errorMessage
,
"message"
,
"message should be correct"
)
assert
.
Equal
(
ui
.
errorMessage
,
"message"
,
"message should be correct"
)
uiClient
.
Message
(
"message"
)
assert
.
Equal
(
ui
.
messageMessage
,
"message"
,
"message should be correct"
)
uiClient
.
Say
(
"message"
)
uiClient
.
Say
(
"message"
)
assert
.
Equal
(
ui
.
sayMessage
,
"message"
,
"message should be correct"
)
assert
.
Equal
(
ui
.
sayMessage
,
"message"
,
"message should be correct"
)
}
}
packer/ui.go
View file @
edab952a
...
@@ -11,14 +11,16 @@ import (
...
@@ -11,14 +11,16 @@ import (
// is formatted and various levels of output.
// is formatted and various levels of output.
type
Ui
interface
{
type
Ui
interface
{
Say
(
string
)
Say
(
string
)
Message
(
string
)
Error
(
string
)
Error
(
string
)
}
}
// PrefixedUi is a UI that wraps another UI implementation and adds a
// PrefixedUi is a UI that wraps another UI implementation and adds a
// prefix to all the messages going out.
// prefix to all the messages going out.
type
PrefixedUi
struct
{
type
PrefixedUi
struct
{
Prefix
string
SayPrefix
string
Ui
Ui
MessagePrefix
string
Ui
Ui
}
}
// The ReaderWriterUi is a UI that writes and reads from standard Go
// The ReaderWriterUi is a UI that writes and reads from standard Go
...
@@ -29,11 +31,15 @@ type ReaderWriterUi struct {
...
@@ -29,11 +31,15 @@ type ReaderWriterUi struct {
}
}
func
(
u
*
PrefixedUi
)
Say
(
message
string
)
{
func
(
u
*
PrefixedUi
)
Say
(
message
string
)
{
u
.
Ui
.
Say
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Prefix
,
message
))
u
.
Ui
.
Say
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
SayPrefix
,
message
))
}
func
(
u
*
PrefixedUi
)
Message
(
message
string
)
{
u
.
Ui
.
Say
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
MessagePrefix
,
message
))
}
}
func
(
u
*
PrefixedUi
)
Error
(
message
string
)
{
func
(
u
*
PrefixedUi
)
Error
(
message
string
)
{
u
.
Ui
.
Error
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Prefix
,
message
))
u
.
Ui
.
Error
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Say
Prefix
,
message
))
}
}
func
(
rw
*
ReaderWriterUi
)
Say
(
message
string
)
{
func
(
rw
*
ReaderWriterUi
)
Say
(
message
string
)
{
...
@@ -44,6 +50,14 @@ func (rw *ReaderWriterUi) Say(message string) {
...
@@ -44,6 +50,14 @@ func (rw *ReaderWriterUi) Say(message string) {
}
}
}
}
func
(
rw
*
ReaderWriterUi
)
Message
(
message
string
)
{
log
.
Printf
(
"ui: %s"
,
message
)
_
,
err
:=
fmt
.
Fprintf
(
rw
.
Writer
,
message
+
"
\n
"
)
if
err
!=
nil
{
panic
(
err
)
}
}
func
(
rw
*
ReaderWriterUi
)
Error
(
message
string
)
{
func
(
rw
*
ReaderWriterUi
)
Error
(
message
string
)
{
log
.
Printf
(
"ui error: %s"
,
message
)
log
.
Printf
(
"ui error: %s"
,
message
)
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
message
+
"
\n
"
)
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
message
+
"
\n
"
)
...
...
packer/ui_test.go
View file @
edab952a
...
@@ -17,11 +17,14 @@ func TestPrefixedUi(t *testing.T) {
...
@@ -17,11 +17,14 @@ func TestPrefixedUi(t *testing.T) {
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
bufferUi
:=
testUi
()
bufferUi
:=
testUi
()
prefixUi
:=
&
PrefixedUi
{
"mitchell"
,
bufferUi
}
prefixUi
:=
&
PrefixedUi
{
"mitchell"
,
"bar"
,
bufferUi
}
prefixUi
.
Say
(
"foo"
)
prefixUi
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"mitchell: foo
\n
"
,
"should have prefix"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"mitchell: foo
\n
"
,
"should have prefix"
)
prefixUi
.
Message
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"bar: foo
\n
"
,
"should have prefix"
)
prefixUi
.
Error
(
"bar"
)
prefixUi
.
Error
(
"bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"mitchell: bar
\n
"
,
"should have prefix"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"mitchell: bar
\n
"
,
"should have prefix"
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment