From a4b5e08fe48dc366dbf493326caf17476d8cab07 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 15 May 2015 21:16:52 -0700 Subject: [PATCH] template/interpolate: upper/lower --- template/interpolate/funcs.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/template/interpolate/funcs.go b/template/interpolate/funcs.go index ead8eb95e..8b081966c 100644 --- a/template/interpolate/funcs.go +++ b/template/interpolate/funcs.go @@ -5,8 +5,11 @@ import ( "fmt" "os" "strconv" + "strings" "text/template" "time" + + "github.com/mitchellh/packer/common/uuid" ) // InitTime is the UTC time when this package was initialized. It is @@ -24,7 +27,11 @@ var FuncGens = map[string]FuncGenerator{ "isotime": funcGenIsotime, "pwd": funcGenPwd, "timestamp": funcGenTimestamp, + "uuid": funcGenUuid, "user": funcGenUser, + + "upper": funcGenPrimitive(strings.ToUpper), + "lower": funcGenPrimitive(strings.ToLower), } // FuncGenerator is a function that given a context generates a template @@ -68,6 +75,12 @@ func funcGenIsotime(ctx *Context) interface{} { } } +func funcGenPrimitive(value interface{}) FuncGenerator { + return func(ctx *Context) interface{} { + return value + } +} + func funcGenPwd(ctx *Context) interface{} { return func() (string, error) { return os.Getwd() @@ -85,3 +98,9 @@ func funcGenUser(ctx *Context) interface{} { return "" } } + +func funcGenUuid(ctx *Context) interface{} { + return func() string { + return uuid.TimeOrderedUUID() + } +}