Commit 548f2ced authored by Zach Zolton's avatar Zach Zolton Committed by Jesse Szwedko

Fix `packer build` reading from STDIN

Signed-off-by: default avatarJesse Szwedko <jesse.szwedko@getbraintree.com>
parent 8fd673ff
......@@ -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
......
......@@ -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),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment