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
97a48e35
Commit
97a48e35
authored
May 23, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
template: ParseFile
parent
d74dacc4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
8 deletions
+14
-8
template/parse.go
template/parse.go
+13
-0
template/parse_test.go
template/parse_test.go
+1
-8
No files found.
template/parse.go
View file @
97a48e35
...
...
@@ -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
)
}
template/parse_test.go
View file @
97a48e35
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
)
}
...
...
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