template: stores the path

This commit is contained in:
Mitchell Hashimoto 2015-05-29 14:05:13 -07:00
parent 2752e51e09
commit 2b9e52e743
3 changed files with 15 additions and 1 deletions

View File

@ -310,5 +310,11 @@ func ParseFile(path string) (*Template, error) {
}
defer f.Close()
return Parse(f)
tpl, err := Parse(f)
if err != nil {
return nil, err
}
tpl.Path = path
return tpl, nil
}

View File

@ -272,11 +272,15 @@ func TestParse(t *testing.T) {
}
for _, tc := range cases {
path := fixtureDir(tc.File)
tpl, err := ParseFile(fixtureDir(tc.File))
if (err != nil) != tc.Err {
t.Fatalf("err: %s", err)
}
if tc.Result != nil {
tc.Result.Path = path
}
if tpl != nil {
tpl.RawContents = nil
}

View File

@ -11,6 +11,10 @@ import (
// Template represents the parsed template that is used to configure
// Packer builds.
type Template struct {
// Path is the path to the template. This will be blank if Parse is
// used, but will be automatically populated by ParseFile.
Path string
Description string
MinVersion string