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
3239d157
Commit
3239d157
authored
Jun 30, 2015
by
Chris Bednarski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2368 from jszwedko/fix-stdin
Fix `packer build` reading from STDIN
parents
3abec949
548f2ced
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
command/build.go
command/build.go
+7
-1
command/build_test.go
command/build_test.go
+30
-0
No files found.
command/build.go
View file @
3239d157
...
...
@@ -37,7 +37,13 @@ func (c BuildCommand) Run(args []string) int {
}
// Parse the template
tpl
,
err
:=
template
.
ParseFile
(
args
[
0
])
var
tpl
*
template
.
Template
var
err
error
if
args
[
0
]
==
"-"
{
tpl
,
err
=
template
.
Parse
(
os
.
Stdin
)
}
else
{
tpl
,
err
=
template
.
ParseFile
(
args
[
0
])
}
if
err
!=
nil
{
c
.
Ui
.
Error
(
fmt
.
Sprintf
(
"Failed to parse template: %s"
,
err
))
return
1
...
...
command/build_test.go
View file @
3239d157
...
...
@@ -37,6 +37,36 @@ func TestBuildOnlyFileCommaFlags(t *testing.T) {
}
}
func
TestBuildStdin
(
t
*
testing
.
T
)
{
c
:=
&
BuildCommand
{
Meta
:
testMetaFile
(
t
),
}
f
,
err
:=
os
.
Open
(
filepath
.
Join
(
testFixture
(
"build-only"
),
"template.json"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
f
.
Close
()
stdin
:=
os
.
Stdin
os
.
Stdin
=
f
defer
func
()
{
os
.
Stdin
=
stdin
}()
defer
cleanup
()
if
code
:=
c
.
Run
([]
string
{
"-"
});
code
!=
0
{
fatalCommand
(
t
,
c
.
Meta
)
}
if
!
fileExists
(
"chocolate.txt"
)
{
t
.
Error
(
"Expected to find chocolate.txt"
)
}
if
!
fileExists
(
"vanilla.txt"
)
{
t
.
Error
(
"Expected to find vanilla.txt"
)
}
if
!
fileExists
(
"cherry.txt"
)
{
t
.
Error
(
"Expected to find cherry.txt"
)
}
}
func
TestBuildOnlyFileMultipleFlags
(
t
*
testing
.
T
)
{
c
:=
&
BuildCommand
{
Meta
:
testMetaFile
(
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