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
1e745d95
Commit
1e745d95
authored
May 15, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
template/interpolate: user variables
parent
a4b5e08f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
2 deletions
+44
-2
template/interpolate/funcs.go
template/interpolate/funcs.go
+6
-2
template/interpolate/funcs_test.go
template/interpolate/funcs_test.go
+34
-0
template/interpolate/i.go
template/interpolate/i.go
+4
-0
No files found.
template/interpolate/funcs.go
View file @
1e745d95
...
...
@@ -94,8 +94,12 @@ func funcGenTimestamp(ctx *Context) interface{} {
}
func
funcGenUser
(
ctx
*
Context
)
interface
{}
{
return
func
()
string
{
return
""
return
func
(
k
string
)
string
{
if
ctx
==
nil
||
ctx
.
UserVariables
==
nil
{
return
""
}
return
ctx
.
UserVariables
[
k
]
}
}
...
...
template/interpolate/funcs_test.go
View file @
1e745d95
...
...
@@ -142,3 +142,37 @@ func TestFuncTimestamp(t *testing.T) {
}
}
}
func
TestFuncUser
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
Input
string
Output
string
}{
{
`{{user "foo"}}`
,
`foo`
,
},
{
`{{user "what"}}`
,
``
,
},
}
ctx
:=
&
Context
{
UserVariables
:
map
[
string
]
string
{
"foo"
:
"foo"
,
},
}
for
_
,
tc
:=
range
cases
{
i
:=
&
I
{
Value
:
tc
.
Input
}
result
,
err
:=
i
.
Render
(
ctx
)
if
err
!=
nil
{
t
.
Fatalf
(
"Input: %s
\n\n
err: %s"
,
tc
.
Input
,
err
)
}
if
result
!=
tc
.
Output
{
t
.
Fatalf
(
"Input: %s
\n\n
Got: %s"
,
tc
.
Input
,
result
)
}
}
}
template/interpolate/i.go
View file @
1e745d95
...
...
@@ -11,6 +11,10 @@ type Context struct {
// Data is the data for the template that is available
Data
interface
{}
// UserVariables is the mapping of user variables that the
// "user" function reads from.
UserVariables
map
[
string
]
string
// DisableEnv disables the env function
DisableEnv
bool
}
...
...
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