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
95153413
Commit
95153413
authored
May 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Ui has Error method
parent
a803af70
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
2 deletions
+43
-2
command/build/command.go
command/build/command.go
+1
-1
packer/rpc/ui.go
packer/rpc/ui.go
+12
-0
packer/rpc/ui_test.go
packer/rpc/ui_test.go
+13
-1
packer/ui.go
packer/ui.go
+5
-0
packer/ui_test.go
packer/ui_test.go
+12
-0
No files found.
command/build/command.go
View file @
95153413
...
...
@@ -9,7 +9,7 @@ type Command byte
func
(
Command
)
Run
(
env
packer
.
Environment
,
args
[]
string
)
int
{
if
len
(
args
)
!=
1
{
// TODO: Error message
env
.
Ui
()
.
Error
(
"A single template argument is required.
\n
"
)
return
1
}
...
...
packer/rpc/ui.go
View file @
95153413
...
...
@@ -22,11 +22,23 @@ type UiSayArgs struct {
Vars
[]
interface
{}
}
func
(
u
*
Ui
)
Error
(
format
string
,
a
...
interface
{})
{
args
:=
&
UiSayArgs
{
format
,
a
}
u
.
client
.
Call
(
"Ui.Error"
,
args
,
new
(
interface
{}))
}
func
(
u
*
Ui
)
Say
(
format
string
,
a
...
interface
{})
{
args
:=
&
UiSayArgs
{
format
,
a
}
u
.
client
.
Call
(
"Ui.Say"
,
args
,
new
(
interface
{}))
}
func
(
u
*
UiServer
)
Error
(
args
*
UiSayArgs
,
reply
*
interface
{})
error
{
u
.
ui
.
Error
(
args
.
Format
,
args
.
Vars
...
)
*
reply
=
nil
return
nil
}
func
(
u
*
UiServer
)
Say
(
args
*
UiSayArgs
,
reply
*
interface
{})
error
{
u
.
ui
.
Say
(
args
.
Format
,
args
.
Vars
...
)
...
...
packer/rpc/ui_test.go
View file @
95153413
...
...
@@ -7,11 +7,20 @@ import (
)
type
testUi
struct
{
errorCalled
bool
errorFormat
string
errorVars
[]
interface
{}
sayCalled
bool
sayFormat
string
sayVars
[]
interface
{}
}
func
(
u
*
testUi
)
Error
(
format
string
,
a
...
interface
{})
{
u
.
errorCalled
=
true
u
.
errorFormat
=
format
u
.
errorVars
=
a
}
func
(
u
*
testUi
)
Say
(
format
string
,
a
...
interface
{})
{
u
.
sayCalled
=
true
u
.
sayFormat
=
format
...
...
@@ -36,7 +45,10 @@ func TestUiRPC(t *testing.T) {
}
uiClient
:=
&
Ui
{
client
}
uiClient
.
Say
(
"format"
,
"arg0"
,
42
)
uiClient
.
Error
(
"format"
,
"arg0"
,
42
)
assert
.
Equal
(
ui
.
errorFormat
,
"format"
,
"format should be correct"
)
uiClient
.
Say
(
"format"
,
"arg0"
,
42
)
assert
.
Equal
(
ui
.
sayFormat
,
"format"
,
"format should be correct"
)
}
packer/ui.go
View file @
95153413
...
...
@@ -8,6 +8,7 @@ import "io"
// is formatted and various levels of output.
type
Ui
interface
{
Say
(
format
string
,
a
...
interface
{})
Error
(
format
string
,
a
...
interface
{})
}
// The ReaderWriterUi is a UI that writes and reads from standard Go
...
...
@@ -20,3 +21,7 @@ type ReaderWriterUi struct {
func
(
rw
*
ReaderWriterUi
)
Say
(
format
string
,
a
...
interface
{})
{
fmt
.
Fprintf
(
rw
.
Writer
,
format
,
a
...
)
}
func
(
rw
*
ReaderWriterUi
)
Error
(
format
string
,
a
...
interface
{})
{
fmt
.
Fprintf
(
rw
.
Writer
,
format
,
a
...
)
}
packer/ui_test.go
View file @
95153413
...
...
@@ -13,6 +13,18 @@ func testUi() *ReaderWriterUi {
}
}
func
TestReaderWriterUi_Error
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
bufferUi
:=
testUi
()
bufferUi
.
Error
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"foo"
,
"basic output"
)
bufferUi
.
Error
(
"%d"
,
5
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"5"
,
"formatting"
)
}
func
TestReaderWriterUi_Say
(
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