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
2788d29b
Commit
2788d29b
authored
May 27, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer, packer/rpc: Update Ui to just take a message
parent
f726ea28
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
39 additions
and
70 deletions
+39
-70
packer/environment.go
packer/environment.go
+1
-1
packer/rpc/build_test.go
packer/rpc/build_test.go
+1
-1
packer/rpc/builder_test.go
packer/rpc/builder_test.go
+1
-1
packer/rpc/environment_test.go
packer/rpc/environment_test.go
+1
-1
packer/rpc/ui.go
packer/rpc/ui.go
+8
-30
packer/rpc/ui_test.go
packer/rpc/ui_test.go
+10
-19
packer/ui.go
packer/ui.go
+12
-14
packer/ui_test.go
packer/ui_test.go
+2
-2
packer/version.go
packer/version.go
+3
-1
No files found.
packer/environment.go
View file @
2788d29b
...
...
@@ -227,7 +227,7 @@ func (e *coreEnvironment) printHelp() {
key
=
fmt
.
Sprintf
(
"%v%v"
,
key
,
strings
.
Repeat
(
" "
,
maxKeyLen
-
len
(
key
)))
// Output the command and the synopsis
e
.
ui
.
Say
(
" %v %v
\n
"
,
key
,
synopsis
)
e
.
ui
.
Say
(
fmt
.
Sprintf
(
" %v %v
\n
"
,
key
,
synopsis
)
)
}
}
...
...
packer/rpc/build_test.go
View file @
2788d29b
...
...
@@ -68,7 +68,7 @@ func TestBuildRPC(t *testing.T) {
if
b
.
runCalled
{
b
.
runUi
.
Say
(
"format"
)
assert
.
True
(
ui
.
sayCalled
,
"say should be called"
)
assert
.
Equal
(
ui
.
say
Format
,
"format"
,
"format
should be correct"
)
assert
.
Equal
(
ui
.
say
Message
,
"format"
,
"message
should be correct"
)
}
}
...
...
packer/rpc/builder_test.go
View file @
2788d29b
...
...
@@ -64,7 +64,7 @@ func TestBuilderRPC(t *testing.T) {
b
.
runUi
.
Say
(
"format"
)
assert
.
True
(
ui
.
sayCalled
,
"say should be called"
)
assert
.
Equal
(
ui
.
say
Format
,
"format"
,
"format
should be correct"
)
assert
.
Equal
(
ui
.
say
Message
,
"format"
,
"message
should be correct"
)
assert
.
Equal
(
artifact
.
Id
(),
testBuilderArtifact
.
Id
(),
"should have artifact Id"
)
}
...
...
packer/rpc/environment_test.go
View file @
2788d29b
...
...
@@ -94,7 +94,7 @@ func TestEnvironmentRPC(t *testing.T) {
// Test calls on the Ui
ui
.
Say
(
"format"
)
assert
.
True
(
testEnvUi
.
sayCalled
,
"Say should be called"
)
assert
.
Equal
(
testEnvUi
.
say
Format
,
"format"
,
"format
should match"
)
assert
.
Equal
(
testEnvUi
.
say
Message
,
"format"
,
"message
should match"
)
}
func
TestEnvironment_ImplementsEnvironment
(
t
*
testing
.
T
)
{
...
...
packer/rpc/ui.go
View file @
2788d29b
...
...
@@ -17,49 +17,27 @@ type UiServer struct {
ui
packer
.
Ui
}
type
UiSayArgs
struct
{
Format
string
Vars
[]
interface
{}
}
func
(
u
*
Ui
)
Error
(
format
string
,
a
...
interface
{})
{
u
.
processArgs
(
a
)
args
:=
&
UiSayArgs
{
format
,
a
}
if
err
:=
u
.
client
.
Call
(
"Ui.Error"
,
args
,
new
(
interface
{}));
err
!=
nil
{
func
(
u
*
Ui
)
Error
(
message
string
)
{
if
err
:=
u
.
client
.
Call
(
"Ui.Error"
,
message
,
new
(
interface
{}));
err
!=
nil
{
panic
(
err
)
}
}
func
(
u
*
Ui
)
Say
(
format
string
,
a
...
interface
{})
{
u
.
processArgs
(
a
)
args
:=
&
UiSayArgs
{
format
,
a
}
if
err
:=
u
.
client
.
Call
(
"Ui.Say"
,
args
,
new
(
interface
{}));
err
!=
nil
{
func
(
u
*
Ui
)
Say
(
message
string
)
{
if
err
:=
u
.
client
.
Call
(
"Ui.Say"
,
message
,
new
(
interface
{}));
err
!=
nil
{
panic
(
err
)
}
}
func
(
u
*
Ui
)
processArgs
(
a
[]
interface
{})
{
// We do some processing to turn certain types into more gob-friendly
// types so that some things that users expect to do just work.
for
i
,
v
:=
range
a
{
// Turn errors into strings
if
err
,
ok
:=
v
.
(
error
);
ok
{
a
[
i
]
=
err
.
Error
()
}
}
}
func
(
u
*
UiServer
)
Error
(
args
*
UiSayArgs
,
reply
*
interface
{})
error
{
u
.
ui
.
Error
(
args
.
Format
,
args
.
Vars
...
)
func
(
u
*
UiServer
)
Error
(
message
*
string
,
reply
*
interface
{})
error
{
u
.
ui
.
Error
(
*
message
)
*
reply
=
nil
return
nil
}
func
(
u
*
UiServer
)
Say
(
args
*
UiSayArgs
,
reply
*
interface
{})
error
{
u
.
ui
.
Say
(
args
.
Format
,
args
.
Vars
...
)
func
(
u
*
UiServer
)
Say
(
message
*
string
,
reply
*
interface
{})
error
{
u
.
ui
.
Say
(
*
message
)
*
reply
=
nil
return
nil
...
...
packer/rpc/ui_test.go
View file @
2788d29b
...
...
@@ -2,30 +2,25 @@ package rpc
import
(
"cgl.tideland.biz/asserts"
"errors"
"net/rpc"
"testing"
)
type
testUi
struct
{
errorCalled
bool
errorFormat
string
errorVars
[]
interface
{}
errorMessage
string
sayCalled
bool
sayFormat
string
sayVars
[]
interface
{}
sayMessage
string
}
func
(
u
*
testUi
)
Error
(
format
string
,
a
...
interface
{}
)
{
func
(
u
*
testUi
)
Error
(
message
string
)
{
u
.
errorCalled
=
true
u
.
errorFormat
=
format
u
.
errorVars
=
a
u
.
errorMessage
=
message
}
func
(
u
*
testUi
)
Say
(
format
string
,
a
...
interface
{}
)
{
func
(
u
*
testUi
)
Say
(
message
string
)
{
u
.
sayCalled
=
true
u
.
sayFormat
=
format
u
.
sayVars
=
a
u
.
sayMessage
=
message
}
func
TestUiRPC
(
t
*
testing
.
T
)
{
...
...
@@ -48,13 +43,9 @@ func TestUiRPC(t *testing.T) {
uiClient
:=
&
Ui
{
client
}
// Basic error and say tests
uiClient
.
Error
(
"
format"
,
"arg0"
,
42
)
assert
.
Equal
(
ui
.
error
Format
,
"format"
,
"format
should be correct"
)
uiClient
.
Error
(
"
message"
)
assert
.
Equal
(
ui
.
error
Message
,
"message"
,
"message
should be correct"
)
uiClient
.
Say
(
"format"
,
"arg0"
,
42
)
assert
.
Equal
(
ui
.
sayFormat
,
"format"
,
"format should be correct"
)
// Test that errors are properly converted to strings
uiClient
.
Say
(
"format"
,
errors
.
New
(
"foo"
))
assert
.
Equal
(
ui
.
sayVars
,
[]
interface
{}{
"foo"
},
"should have correct vars"
)
uiClient
.
Say
(
"message"
)
assert
.
Equal
(
ui
.
sayMessage
,
"message"
,
"message should be correct"
)
}
packer/ui.go
View file @
2788d29b
...
...
@@ -10,8 +10,8 @@ import (
// world. This sort of control allows us to strictly control how output
// is formatted and various levels of output.
type
Ui
interface
{
Say
(
format
string
,
a
...
interface
{}
)
Error
(
format
string
,
a
...
interface
{}
)
Say
(
string
)
Error
(
string
)
}
// PrefixedUi is a UI that wraps another UI implementation and adds a
...
...
@@ -28,27 +28,25 @@ 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
)
Say
(
message
string
)
{
u
.
Ui
.
Say
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Prefix
,
message
)
)
}
func
(
u
*
PrefixedUi
)
Error
(
format
string
,
a
...
interface
{}
)
{
u
.
Ui
.
Error
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Prefix
,
format
),
a
...
)
func
(
u
*
PrefixedUi
)
Error
(
message
string
)
{
u
.
Ui
.
Error
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Prefix
,
message
)
)
}
func
(
rw
*
ReaderWriterUi
)
Say
(
format
string
,
a
...
interface
{})
{
output
:=
fmt
.
Sprintf
(
format
,
a
...
)
log
.
Printf
(
"ui: %s"
,
output
)
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
output
+
"
\n
"
)
func
(
rw
*
ReaderWriterUi
)
Say
(
message
string
)
{
log
.
Printf
(
"ui: %s"
,
message
)
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
message
+
"
\n
"
)
if
err
!=
nil
{
panic
(
err
)
}
}
func
(
rw
*
ReaderWriterUi
)
Error
(
format
string
,
a
...
interface
{})
{
output
:=
fmt
.
Sprintf
(
format
,
a
...
)
log
.
Printf
(
"ui error: %s"
,
output
)
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
output
+
"
\n
"
)
func
(
rw
*
ReaderWriterUi
)
Error
(
message
string
)
{
log
.
Printf
(
"ui error: %s"
,
message
)
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
message
+
"
\n
"
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
packer/ui_test.go
View file @
2788d29b
...
...
@@ -50,7 +50,7 @@ func TestReaderWriterUi_Error(t *testing.T) {
bufferUi
.
Error
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"foo
\n
"
,
"basic output"
)
bufferUi
.
Error
(
"
%d"
,
5
)
bufferUi
.
Error
(
"
5"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"5
\n
"
,
"formatting"
)
}
...
...
@@ -62,7 +62,7 @@ func TestReaderWriterUi_Say(t *testing.T) {
bufferUi
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"foo
\n
"
,
"basic output"
)
bufferUi
.
Say
(
"
%d"
,
5
)
bufferUi
.
Say
(
"
5"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"5
\n
"
,
"formatting"
)
}
...
...
packer/version.go
View file @
2788d29b
package
packer
import
"fmt"
// The version of packer.
const
Version
=
"0.1.0.dev"
...
...
@@ -7,7 +9,7 @@ type versionCommand byte
// Implement the Command interface by simply showing the version
func
(
versionCommand
)
Run
(
env
Environment
,
args
[]
string
)
int
{
env
.
Ui
()
.
Say
(
"Packer v%v
\n
"
,
Version
)
env
.
Ui
()
.
Say
(
fmt
.
Sprintf
(
"Packer v%v
\n
"
,
Version
)
)
return
0
}
...
...
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