mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-11 01:30:06 -04:00
template: ParseFile
This commit is contained in:
parent
d74dacc4c0
commit
97a48e35bb
2 changed files with 14 additions and 8 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
|
|
@ -290,3 +291,15 @@ func Parse(r io.Reader) (*Template, error) {
|
|||
// Return the template parsed from the raw structure
|
||||
return rawTpl.Template()
|
||||
}
|
||||
|
||||
// ParseFile is the same as Parse but is a helper to automatically open
|
||||
// a file for parsing.
|
||||
func ParseFile(path string) (*Template, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return Parse(f)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package template
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -272,13 +271,7 @@ func TestParse(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
f, err := os.Open(fixtureDir(tc.File))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
tpl, err := Parse(f)
|
||||
f.Close()
|
||||
tpl, err := ParseFile(fixtureDir(tc.File))
|
||||
if (err != nil) != tc.Err {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue