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
03c10a9a
Commit
03c10a9a
authored
Aug 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: renamed PrefixedUi to TargettedUi
parent
02edc757
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
39 deletions
+47
-39
packer/build.go
packer/build.go
+7
-9
packer/ui.go
packer/ui.go
+24
-17
packer/ui_test.go
packer/ui_test.go
+16
-13
No files found.
packer/build.go
View file @
03c10a9a
...
@@ -213,11 +213,10 @@ func (b *coreBuild) Run(originalUi Ui, cache Cache) ([]Artifact, error) {
...
@@ -213,11 +213,10 @@ func (b *coreBuild) Run(originalUi Ui, cache Cache) ([]Artifact, error) {
hook
:=
&
DispatchHook
{
hooks
}
hook
:=
&
DispatchHook
{
hooks
}
artifacts
:=
make
([]
Artifact
,
0
,
1
)
artifacts
:=
make
([]
Artifact
,
0
,
1
)
// The builder just has a normal Ui, but prefixed
// The builder just has a normal Ui, but targetted
builderUi
:=
&
PrefixedUi
{
builderUi
:=
&
TargettedUi
{
fmt
.
Sprintf
(
"==> %s"
,
b
.
Name
()),
Target
:
b
.
Name
(),
fmt
.
Sprintf
(
" %s"
,
b
.
Name
()),
Ui
:
originalUi
,
originalUi
,
}
}
log
.
Printf
(
"Running builder: %s"
,
b
.
builderType
)
log
.
Printf
(
"Running builder: %s"
,
b
.
builderType
)
...
@@ -240,10 +239,9 @@ PostProcessorRunSeqLoop:
...
@@ -240,10 +239,9 @@ PostProcessorRunSeqLoop:
for
_
,
ppSeq
:=
range
b
.
postProcessors
{
for
_
,
ppSeq
:=
range
b
.
postProcessors
{
priorArtifact
:=
builderArtifact
priorArtifact
:=
builderArtifact
for
i
,
corePP
:=
range
ppSeq
{
for
i
,
corePP
:=
range
ppSeq
{
ppUi
:=
&
PrefixedUi
{
ppUi
:=
&
TargettedUi
{
fmt
.
Sprintf
(
"==> %s (%s)"
,
b
.
Name
(),
corePP
.
processorType
),
Target
:
fmt
.
Sprintf
(
"%s (%s)"
,
b
.
Name
(),
corePP
.
processorType
),
fmt
.
Sprintf
(
" %s (%s)"
,
b
.
Name
(),
corePP
.
processorType
),
Ui
:
originalUi
,
originalUi
,
}
}
builderUi
.
Say
(
fmt
.
Sprintf
(
"Running post-processor: %s"
,
corePP
.
processorType
))
builderUi
.
Say
(
fmt
.
Sprintf
(
"Running post-processor: %s"
,
corePP
.
processorType
))
...
...
packer/ui.go
View file @
03c10a9a
...
@@ -43,12 +43,14 @@ type ColoredUi struct {
...
@@ -43,12 +43,14 @@ type ColoredUi struct {
Ui
Ui
Ui
Ui
}
}
// PrefixedUi is a UI that wraps another UI implementation and adds a
// TargettedUi is a UI that wraps another UI implementation and modifies
// prefix to all the messages going out.
// the output to indicate a specific target. Specifically, all Say output
type
PrefixedUi
struct
{
// is prefixed with the target name. Message output is not prefixed but
SayPrefix
string
// is offset by the length of the target so that output is lined up properly
MessagePrefix
string
// with Say output. Machine-readable output has the proper target set.
Ui
Ui
type
TargettedUi
struct
{
Target
string
Ui
Ui
}
}
// The BasicUI is a UI that reads and writes from a standard Go reader
// The BasicUI is a UI that reads and writes from a standard Go reader
...
@@ -116,32 +118,37 @@ func (u *ColoredUi) supportsColors() bool {
...
@@ -116,32 +118,37 @@ func (u *ColoredUi) supportsColors() bool {
return
cygwin
return
cygwin
}
}
func
(
u
*
Prefix
edUi
)
Ask
(
query
string
)
(
string
,
error
)
{
func
(
u
*
Targett
edUi
)
Ask
(
query
string
)
(
string
,
error
)
{
return
u
.
Ui
.
Ask
(
u
.
prefixLines
(
u
.
SayPrefix
,
query
))
return
u
.
Ui
.
Ask
(
u
.
prefixLines
(
true
,
query
))
}
}
func
(
u
*
Prefix
edUi
)
Say
(
message
string
)
{
func
(
u
*
Targett
edUi
)
Say
(
message
string
)
{
u
.
Ui
.
Say
(
u
.
prefixLines
(
u
.
SayPrefix
,
message
))
u
.
Ui
.
Say
(
u
.
prefixLines
(
true
,
message
))
}
}
func
(
u
*
Prefix
edUi
)
Message
(
message
string
)
{
func
(
u
*
Targett
edUi
)
Message
(
message
string
)
{
u
.
Ui
.
Message
(
u
.
prefixLines
(
u
.
MessagePrefix
,
message
))
u
.
Ui
.
Message
(
u
.
prefixLines
(
false
,
message
))
}
}
func
(
u
*
Prefix
edUi
)
Error
(
message
string
)
{
func
(
u
*
Targett
edUi
)
Error
(
message
string
)
{
u
.
Ui
.
Error
(
u
.
prefixLines
(
u
.
SayPrefix
,
message
))
u
.
Ui
.
Error
(
u
.
prefixLines
(
true
,
message
))
}
}
func
(
u
*
Prefix
edUi
)
Machine
(
t
string
,
args
...
string
)
{
func
(
u
*
Targett
edUi
)
Machine
(
t
string
,
args
...
string
)
{
// Just pass it through for now.
// Just pass it through for now.
u
.
Ui
.
Machine
(
t
,
args
...
)
u
.
Ui
.
Machine
(
t
,
args
...
)
}
}
func
(
u
*
PrefixedUi
)
prefixLines
(
prefix
,
message
string
)
string
{
func
(
u
*
TargettedUi
)
prefixLines
(
arrow
bool
,
message
string
)
string
{
arrowText
:=
"==>"
if
!
arrow
{
arrowText
=
strings
.
Repeat
(
" "
,
len
(
arrowText
))
}
var
result
bytes
.
Buffer
var
result
bytes
.
Buffer
for
_
,
line
:=
range
strings
.
Split
(
message
,
"
\n
"
)
{
for
_
,
line
:=
range
strings
.
Split
(
message
,
"
\n
"
)
{
result
.
WriteString
(
fmt
.
Sprintf
(
"%s
: %s
\n
"
,
prefix
,
line
))
result
.
WriteString
(
fmt
.
Sprintf
(
"%s
%s: %s
\n
"
,
arrowText
,
u
.
Target
,
line
))
}
}
return
strings
.
TrimRightFunc
(
result
.
String
(),
unicode
.
IsSpace
)
return
strings
.
TrimRightFunc
(
result
.
String
(),
unicode
.
IsSpace
)
...
...
packer/ui_test.go
View file @
03c10a9a
...
@@ -36,23 +36,26 @@ func TestColoredUi(t *testing.T) {
...
@@ -36,23 +36,26 @@ func TestColoredUi(t *testing.T) {
}
}
}
}
func
Test
Prefix
edUi
(
t
*
testing
.
T
)
{
func
Test
Targett
edUi
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
bufferUi
:=
testUi
()
bufferUi
:=
testUi
()
prefixUi
:=
&
PrefixedUi
{
"mitchell"
,
"bar"
,
bufferUi
}
TargettedUi
:=
&
TargettedUi
{
Target
:
"foo"
,
Ui
:
bufferUi
,
}
prefix
Ui
.
Say
(
"foo"
)
Targetted
Ui
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
mitchell
: foo
\n
"
,
"should have prefix"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
==> foo
: foo
\n
"
,
"should have prefix"
)
prefix
Ui
.
Message
(
"foo"
)
Targetted
Ui
.
Message
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
bar
: foo
\n
"
,
"should have prefix"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
foo
: foo
\n
"
,
"should have prefix"
)
prefix
Ui
.
Error
(
"bar"
)
Targetted
Ui
.
Error
(
"bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
mitchell
: bar
\n
"
,
"should have prefix"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
==> foo
: bar
\n
"
,
"should have prefix"
)
prefix
Ui
.
Say
(
"foo
\n
bar"
)
Targetted
Ui
.
Say
(
"foo
\n
bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
mitchell: foo
\n
mitchell
: bar
\n
"
,
"should multiline"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
==> foo: foo
\n
==> foo
: bar
\n
"
,
"should multiline"
)
}
}
func
TestColoredUi_ImplUi
(
t
*
testing
.
T
)
{
func
TestColoredUi_ImplUi
(
t
*
testing
.
T
)
{
...
@@ -63,11 +66,11 @@ func TestColoredUi_ImplUi(t *testing.T) {
...
@@ -63,11 +66,11 @@ func TestColoredUi_ImplUi(t *testing.T) {
}
}
}
}
func
Test
Prefix
edUi_ImplUi
(
t
*
testing
.
T
)
{
func
Test
Targett
edUi_ImplUi
(
t
*
testing
.
T
)
{
var
raw
interface
{}
var
raw
interface
{}
raw
=
&
Prefix
edUi
{}
raw
=
&
Targett
edUi
{}
if
_
,
ok
:=
raw
.
(
Ui
);
!
ok
{
if
_
,
ok
:=
raw
.
(
Ui
);
!
ok
{
t
.
Fatalf
(
"
Prefix
edUi must implement Ui"
)
t
.
Fatalf
(
"
Targett
edUi must implement Ui"
)
}
}
}
}
...
...
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