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() {
...
@@ -227,7 +227,7 @@ func (e *coreEnvironment) printHelp() {
key
=
fmt
.
Sprintf
(
"%v%v"
,
key
,
strings
.
Repeat
(
" "
,
maxKeyLen
-
len
(
key
)))
key
=
fmt
.
Sprintf
(
"%v%v"
,
key
,
strings
.
Repeat
(
" "
,
maxKeyLen
-
len
(
key
)))
// Output the command and the synopsis
// 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) {
...
@@ -68,7 +68,7 @@ func TestBuildRPC(t *testing.T) {
if
b
.
runCalled
{
if
b
.
runCalled
{
b
.
runUi
.
Say
(
"format"
)
b
.
runUi
.
Say
(
"format"
)
assert
.
True
(
ui
.
sayCalled
,
"say should be called"
)
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) {
...
@@ -64,7 +64,7 @@ func TestBuilderRPC(t *testing.T) {
b
.
runUi
.
Say
(
"format"
)
b
.
runUi
.
Say
(
"format"
)
assert
.
True
(
ui
.
sayCalled
,
"say should be called"
)
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"
)
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) {
...
@@ -94,7 +94,7 @@ func TestEnvironmentRPC(t *testing.T) {
// Test calls on the Ui
// Test calls on the Ui
ui
.
Say
(
"format"
)
ui
.
Say
(
"format"
)
assert
.
True
(
testEnvUi
.
sayCalled
,
"Say should be called"
)
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
)
{
func
TestEnvironment_ImplementsEnvironment
(
t
*
testing
.
T
)
{
...
...
packer/rpc/ui.go
View file @
2788d29b
...
@@ -17,49 +17,27 @@ type UiServer struct {
...
@@ -17,49 +17,27 @@ type UiServer struct {
ui
packer
.
Ui
ui
packer
.
Ui
}
}
type
UiSayArgs
struct
{
func
(
u
*
Ui
)
Error
(
message
string
)
{
Format
string
if
err
:=
u
.
client
.
Call
(
"Ui.Error"
,
message
,
new
(
interface
{}));
err
!=
nil
{
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
{
panic
(
err
)
panic
(
err
)
}
}
}
}
func
(
u
*
Ui
)
Say
(
format
string
,
a
...
interface
{})
{
func
(
u
*
Ui
)
Say
(
message
string
)
{
u
.
processArgs
(
a
)
if
err
:=
u
.
client
.
Call
(
"Ui.Say"
,
message
,
new
(
interface
{}));
err
!=
nil
{
args
:=
&
UiSayArgs
{
format
,
a
}
if
err
:=
u
.
client
.
Call
(
"Ui.Say"
,
args
,
new
(
interface
{}));
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
}
}
func
(
u
*
Ui
)
processArgs
(
a
[]
interface
{})
{
func
(
u
*
UiServer
)
Error
(
message
*
string
,
reply
*
interface
{})
error
{
// We do some processing to turn certain types into more gob-friendly
u
.
ui
.
Error
(
*
message
)
// 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
...
)
*
reply
=
nil
*
reply
=
nil
return
nil
return
nil
}
}
func
(
u
*
UiServer
)
Say
(
args
*
UiSayArgs
,
reply
*
interface
{})
error
{
func
(
u
*
UiServer
)
Say
(
message
*
string
,
reply
*
interface
{})
error
{
u
.
ui
.
Say
(
args
.
Format
,
args
.
Vars
...
)
u
.
ui
.
Say
(
*
message
)
*
reply
=
nil
*
reply
=
nil
return
nil
return
nil
...
...
packer/rpc/ui_test.go
View file @
2788d29b
...
@@ -2,30 +2,25 @@ package rpc
...
@@ -2,30 +2,25 @@ package rpc
import
(
import
(
"cgl.tideland.biz/asserts"
"cgl.tideland.biz/asserts"
"errors"
"net/rpc"
"net/rpc"
"testing"
"testing"
)
)
type
testUi
struct
{
type
testUi
struct
{
errorCalled
bool
errorCalled
bool
errorFormat
string
errorMessage
string
errorVars
[]
interface
{}
sayCalled
bool
sayCalled
bool
sayFormat
string
sayMessage
string
sayVars
[]
interface
{}
}
}
func
(
u
*
testUi
)
Error
(
format
string
,
a
...
interface
{}
)
{
func
(
u
*
testUi
)
Error
(
message
string
)
{
u
.
errorCalled
=
true
u
.
errorCalled
=
true
u
.
errorFormat
=
format
u
.
errorMessage
=
message
u
.
errorVars
=
a
}
}
func
(
u
*
testUi
)
Say
(
format
string
,
a
...
interface
{}
)
{
func
(
u
*
testUi
)
Say
(
message
string
)
{
u
.
sayCalled
=
true
u
.
sayCalled
=
true
u
.
sayFormat
=
format
u
.
sayMessage
=
message
u
.
sayVars
=
a
}
}
func
TestUiRPC
(
t
*
testing
.
T
)
{
func
TestUiRPC
(
t
*
testing
.
T
)
{
...
@@ -48,13 +43,9 @@ func TestUiRPC(t *testing.T) {
...
@@ -48,13 +43,9 @@ func TestUiRPC(t *testing.T) {
uiClient
:=
&
Ui
{
client
}
uiClient
:=
&
Ui
{
client
}
// Basic error and say tests
// Basic error and say tests
uiClient
.
Error
(
"
format"
,
"arg0"
,
42
)
uiClient
.
Error
(
"
message"
)
assert
.
Equal
(
ui
.
error
Format
,
"format"
,
"format
should be correct"
)
assert
.
Equal
(
ui
.
error
Message
,
"message"
,
"message
should be correct"
)
uiClient
.
Say
(
"format"
,
"arg0"
,
42
)
uiClient
.
Say
(
"message"
)
assert
.
Equal
(
ui
.
sayFormat
,
"format"
,
"format should be correct"
)
assert
.
Equal
(
ui
.
sayMessage
,
"message"
,
"message 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"
)
}
}
packer/ui.go
View file @
2788d29b
...
@@ -10,8 +10,8 @@ import (
...
@@ -10,8 +10,8 @@ import (
// world. This sort of control allows us to strictly control how output
// world. This sort of control allows us to strictly control how output
// is formatted and various levels of output.
// is formatted and various levels of output.
type
Ui
interface
{
type
Ui
interface
{
Say
(
format
string
,
a
...
interface
{}
)
Say
(
string
)
Error
(
format
string
,
a
...
interface
{}
)
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
...
@@ -28,27 +28,25 @@ type ReaderWriterUi struct {
...
@@ -28,27 +28,25 @@ type ReaderWriterUi struct {
Writer
io
.
Writer
Writer
io
.
Writer
}
}
func
(
u
*
PrefixedUi
)
Say
(
format
string
,
a
...
interface
{}
)
{
func
(
u
*
PrefixedUi
)
Say
(
message
string
)
{
u
.
Ui
.
Say
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Prefix
,
format
),
a
...
)
u
.
Ui
.
Say
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Prefix
,
message
)
)
}
}
func
(
u
*
PrefixedUi
)
Error
(
format
string
,
a
...
interface
{}
)
{
func
(
u
*
PrefixedUi
)
Error
(
message
string
)
{
u
.
Ui
.
Error
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Prefix
,
format
),
a
...
)
u
.
Ui
.
Error
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
Prefix
,
message
)
)
}
}
func
(
rw
*
ReaderWriterUi
)
Say
(
format
string
,
a
...
interface
{})
{
func
(
rw
*
ReaderWriterUi
)
Say
(
message
string
)
{
output
:=
fmt
.
Sprintf
(
format
,
a
...
)
log
.
Printf
(
"ui: %s"
,
message
)
log
.
Printf
(
"ui: %s"
,
output
)
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
message
+
"
\n
"
)
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
output
+
"
\n
"
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
}
}
func
(
rw
*
ReaderWriterUi
)
Error
(
format
string
,
a
...
interface
{})
{
func
(
rw
*
ReaderWriterUi
)
Error
(
message
string
)
{
output
:=
fmt
.
Sprintf
(
format
,
a
...
)
log
.
Printf
(
"ui error: %s"
,
message
)
log
.
Printf
(
"ui error: %s"
,
output
)
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
message
+
"
\n
"
)
_
,
err
:=
fmt
.
Fprint
(
rw
.
Writer
,
output
+
"
\n
"
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
...
...
packer/ui_test.go
View file @
2788d29b
...
@@ -50,7 +50,7 @@ func TestReaderWriterUi_Error(t *testing.T) {
...
@@ -50,7 +50,7 @@ func TestReaderWriterUi_Error(t *testing.T) {
bufferUi
.
Error
(
"foo"
)
bufferUi
.
Error
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"foo
\n
"
,
"basic output"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"foo
\n
"
,
"basic output"
)
bufferUi
.
Error
(
"
%d"
,
5
)
bufferUi
.
Error
(
"
5"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"5
\n
"
,
"formatting"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"5
\n
"
,
"formatting"
)
}
}
...
@@ -62,7 +62,7 @@ func TestReaderWriterUi_Say(t *testing.T) {
...
@@ -62,7 +62,7 @@ func TestReaderWriterUi_Say(t *testing.T) {
bufferUi
.
Say
(
"foo"
)
bufferUi
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"foo
\n
"
,
"basic output"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"foo
\n
"
,
"basic output"
)
bufferUi
.
Say
(
"
%d"
,
5
)
bufferUi
.
Say
(
"
5"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"5
\n
"
,
"formatting"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"5
\n
"
,
"formatting"
)
}
}
...
...
packer/version.go
View file @
2788d29b
package
packer
package
packer
import
"fmt"
// The version of packer.
// The version of packer.
const
Version
=
"0.1.0.dev"
const
Version
=
"0.1.0.dev"
...
@@ -7,7 +9,7 @@ type versionCommand byte
...
@@ -7,7 +9,7 @@ type versionCommand byte
// Implement the Command interface by simply showing the version
// Implement the Command interface by simply showing the version
func
(
versionCommand
)
Run
(
env
Environment
,
args
[]
string
)
int
{
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
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