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) {
hook
:=
&
DispatchHook
{
hooks
}
artifacts
:=
make
([]
Artifact
,
0
,
1
)
// The builder just has a normal Ui, but prefixed
builderUi
:=
&
PrefixedUi
{
fmt
.
Sprintf
(
"==> %s"
,
b
.
Name
()),
fmt
.
Sprintf
(
" %s"
,
b
.
Name
()),
originalUi
,
// The builder just has a normal Ui, but targetted
builderUi
:=
&
TargettedUi
{
Target
:
b
.
Name
(),
Ui
:
originalUi
,
}
log
.
Printf
(
"Running builder: %s"
,
b
.
builderType
)
...
...
@@ -240,10 +239,9 @@ PostProcessorRunSeqLoop:
for
_
,
ppSeq
:=
range
b
.
postProcessors
{
priorArtifact
:=
builderArtifact
for
i
,
corePP
:=
range
ppSeq
{
ppUi
:=
&
PrefixedUi
{
fmt
.
Sprintf
(
"==> %s (%s)"
,
b
.
Name
(),
corePP
.
processorType
),
fmt
.
Sprintf
(
" %s (%s)"
,
b
.
Name
(),
corePP
.
processorType
),
originalUi
,
ppUi
:=
&
TargettedUi
{
Target
:
fmt
.
Sprintf
(
"%s (%s)"
,
b
.
Name
(),
corePP
.
processorType
),
Ui
:
originalUi
,
}
builderUi
.
Say
(
fmt
.
Sprintf
(
"Running post-processor: %s"
,
corePP
.
processorType
))
...
...
packer/ui.go
View file @
03c10a9a
...
...
@@ -43,12 +43,14 @@ type ColoredUi struct {
Ui
Ui
}
// PrefixedUi is a UI that wraps another UI implementation and adds a
// prefix to all the messages going out.
type
PrefixedUi
struct
{
SayPrefix
string
MessagePrefix
string
Ui
Ui
// TargettedUi is a UI that wraps another UI implementation and modifies
// the output to indicate a specific target. Specifically, all Say output
// is prefixed with the target name. Message output is not prefixed but
// is offset by the length of the target so that output is lined up properly
// with Say output. Machine-readable output has the proper target set.
type
TargettedUi
struct
{
Target
string
Ui
Ui
}
// The BasicUI is a UI that reads and writes from a standard Go reader
...
...
@@ -116,32 +118,37 @@ func (u *ColoredUi) supportsColors() bool {
return
cygwin
}
func
(
u
*
Prefix
edUi
)
Ask
(
query
string
)
(
string
,
error
)
{
return
u
.
Ui
.
Ask
(
u
.
prefixLines
(
u
.
SayPrefix
,
query
))
func
(
u
*
Targett
edUi
)
Ask
(
query
string
)
(
string
,
error
)
{
return
u
.
Ui
.
Ask
(
u
.
prefixLines
(
true
,
query
))
}
func
(
u
*
Prefix
edUi
)
Say
(
message
string
)
{
u
.
Ui
.
Say
(
u
.
prefixLines
(
u
.
SayPrefix
,
message
))
func
(
u
*
Targett
edUi
)
Say
(
message
string
)
{
u
.
Ui
.
Say
(
u
.
prefixLines
(
true
,
message
))
}
func
(
u
*
Prefix
edUi
)
Message
(
message
string
)
{
u
.
Ui
.
Message
(
u
.
prefixLines
(
u
.
MessagePrefix
,
message
))
func
(
u
*
Targett
edUi
)
Message
(
message
string
)
{
u
.
Ui
.
Message
(
u
.
prefixLines
(
false
,
message
))
}
func
(
u
*
Prefix
edUi
)
Error
(
message
string
)
{
u
.
Ui
.
Error
(
u
.
prefixLines
(
u
.
SayPrefix
,
message
))
func
(
u
*
Targett
edUi
)
Error
(
message
string
)
{
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.
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
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
)
...
...
packer/ui_test.go
View file @
03c10a9a
...
...
@@ -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
)
bufferUi
:=
testUi
()
prefixUi
:=
&
PrefixedUi
{
"mitchell"
,
"bar"
,
bufferUi
}
TargettedUi
:=
&
TargettedUi
{
Target
:
"foo"
,
Ui
:
bufferUi
,
}
prefix
Ui
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
mitchell
: foo
\n
"
,
"should have prefix"
)
Targetted
Ui
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
==> foo
: foo
\n
"
,
"should have prefix"
)
prefix
Ui
.
Message
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
bar
: foo
\n
"
,
"should have prefix"
)
Targetted
Ui
.
Message
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
foo
: foo
\n
"
,
"should have prefix"
)
prefix
Ui
.
Error
(
"bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
mitchell
: bar
\n
"
,
"should have prefix"
)
Targetted
Ui
.
Error
(
"bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
==> foo
: bar
\n
"
,
"should have prefix"
)
prefix
Ui
.
Say
(
"foo
\n
bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
mitchell: foo
\n
mitchell
: bar
\n
"
,
"should multiline"
)
Targetted
Ui
.
Say
(
"foo
\n
bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
==> foo: foo
\n
==> foo
: bar
\n
"
,
"should multiline"
)
}
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
{}
raw
=
&
Prefix
edUi
{}
raw
=
&
Targett
edUi
{}
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