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
2c4a873a
Commit
2c4a873a
authored
May 21, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Add PrefixedUi
parent
cc4970d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
packer/ui.go
packer/ui.go
+15
-0
packer/ui_test.go
packer/ui_test.go
+29
-0
No files found.
packer/ui.go
View file @
2c4a873a
...
...
@@ -14,6 +14,13 @@ type Ui interface {
Error
(
format
string
,
a
...
interface
{})
}
// 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
}
// The ReaderWriterUi is a UI that writes and reads from standard Go
// io.Reader and io.Writer.
type
ReaderWriterUi
struct
{
...
...
@@ -21,6 +28,14 @@ type ReaderWriterUi struct {
Writer
io
.
Writer
}
func
(
u
*
PrefixedUi
)
Say
(
format
string
,
a
...
interface
{})
{
u
.
Ui
.
Say
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Prefix
,
format
),
a
...
)
}
func
(
u
*
PrefixedUi
)
Error
(
format
string
,
a
...
interface
{})
{
u
.
Ui
.
Error
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Prefix
,
format
),
a
...
)
}
func
(
rw
*
ReaderWriterUi
)
Say
(
format
string
,
a
...
interface
{})
{
output
:=
fmt
.
Sprintf
(
format
,
a
...
)
log
.
Printf
(
"ui: %s"
,
output
)
...
...
packer/ui_test.go
View file @
2c4a873a
...
...
@@ -13,6 +13,35 @@ func testUi() *ReaderWriterUi {
}
}
func
TestPrefixedUi
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
bufferUi
:=
testUi
()
prefixUi
:=
&
PrefixedUi
{
"mitchell"
,
bufferUi
}
prefixUi
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"mitchell: foo
\n
"
,
"should have prefix"
)
prefixUi
.
Error
(
"bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"mitchell: bar
\n
"
,
"should have prefix"
)
}
func
TestPrefixedUi_ImplUi
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
PrefixedUi
{}
if
_
,
ok
:=
raw
.
(
Ui
);
!
ok
{
t
.
Fatalf
(
"PrefixedUi must implement Ui"
)
}
}
func
TestReaderWriterUi_ImplUi
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
ReaderWriterUi
{}
if
_
,
ok
:=
raw
.
(
Ui
);
!
ok
{
t
.
Fatalf
(
"ReaderWriterUi must implement Ui"
)
}
}
func
TestReaderWriterUi_Error
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
...
...
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