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
7198936f
Commit
7198936f
authored
Jul 02, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: PrefixedUi properly prefixes each line of output
parent
874b4acf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
4 deletions
+19
-4
packer/ui.go
packer/ui.go
+16
-4
packer/ui_test.go
packer/ui_test.go
+3
-0
No files found.
packer/ui.go
View file @
7198936f
package
packer
package
packer
import
(
import
(
"bytes"
"errors"
"errors"
"fmt"
"fmt"
"io"
"io"
"log"
"log"
"os"
"os"
"os/signal"
"os/signal"
"strings"
"sync"
"sync"
)
)
...
@@ -86,19 +88,29 @@ func (u *ColoredUi) colorize(message string, color UiColor, bold bool) string {
...
@@ -86,19 +88,29 @@ func (u *ColoredUi) colorize(message string, color UiColor, bold bool) string {
}
}
func
(
u
*
PrefixedUi
)
Ask
(
query
string
)
(
string
,
error
)
{
func
(
u
*
PrefixedUi
)
Ask
(
query
string
)
(
string
,
error
)
{
return
u
.
Ui
.
Ask
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
SayPrefix
,
query
))
return
u
.
Ui
.
Ask
(
u
.
prefixLines
(
u
.
SayPrefix
,
query
))
}
}
func
(
u
*
PrefixedUi
)
Say
(
message
string
)
{
func
(
u
*
PrefixedUi
)
Say
(
message
string
)
{
u
.
Ui
.
Say
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
SayPrefix
,
message
))
u
.
Ui
.
Say
(
u
.
prefixLines
(
u
.
SayPrefix
,
message
))
}
}
func
(
u
*
PrefixedUi
)
Message
(
message
string
)
{
func
(
u
*
PrefixedUi
)
Message
(
message
string
)
{
u
.
Ui
.
Message
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
MessagePrefix
,
message
))
u
.
Ui
.
Message
(
u
.
prefixLines
(
u
.
MessagePrefix
,
message
))
}
}
func
(
u
*
PrefixedUi
)
Error
(
message
string
)
{
func
(
u
*
PrefixedUi
)
Error
(
message
string
)
{
u
.
Ui
.
Error
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
SayPrefix
,
message
))
u
.
Ui
.
Error
(
u
.
prefixLines
(
u
.
SayPrefix
,
message
))
}
func
(
u
*
PrefixedUi
)
prefixLines
(
prefix
,
message
string
)
string
{
var
result
bytes
.
Buffer
for
_
,
line
:=
range
strings
.
Split
(
message
,
"
\n
"
)
{
result
.
WriteString
(
fmt
.
Sprintf
(
"%s: %s
\n
"
,
prefix
,
line
))
}
return
strings
.
TrimSpace
(
result
.
String
())
}
}
func
(
rw
*
ReaderWriterUi
)
Ask
(
query
string
)
(
string
,
error
)
{
func
(
rw
*
ReaderWriterUi
)
Ask
(
query
string
)
(
string
,
error
)
{
...
...
packer/ui_test.go
View file @
7198936f
...
@@ -50,6 +50,9 @@ func TestPrefixedUi(t *testing.T) {
...
@@ -50,6 +50,9 @@ func TestPrefixedUi(t *testing.T) {
prefixUi
.
Error
(
"bar"
)
prefixUi
.
Error
(
"bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"mitchell: bar
\n
"
,
"should have prefix"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"mitchell: bar
\n
"
,
"should have prefix"
)
prefixUi
.
Say
(
"foo
\n
bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"mitchell: foo
\n
mitchell: bar
\n
"
,
"should multiline"
)
}
}
func
TestColoredUi_ImplUi
(
t
*
testing
.
T
)
{
func
TestColoredUi_ImplUi
(
t
*
testing
.
T
)
{
...
...
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