Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 8f9f533

Browse files
kaufersDavid Chung
authored andcommitted
Support int and bool types as template CLI vars (#543)
Signed-off-by: Steven Kaufer <[email protected]>
1 parent 12aaeda commit 8f9f533

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmd/infrakit/base/template.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io/ioutil"
66
"os"
77
"path"
8+
"strconv"
89
"strings"
910

1011
"github.com/docker/infrakit/pkg/cli"
@@ -131,7 +132,15 @@ func TemplateProcessor(plugins func() discovery.Plugins) (*pflag.FlagSet, ToJSON
131132
key := strings.TrimSpace(kv[0])
132133
val := strings.TrimSpace(kv[1])
133134
if key != "" && val != "" {
134-
engine.Global(key, val)
135+
// Attempt to convert to int and bool types so that template operations
136+
// are not only against strings.
137+
if intVal, err := strconv.Atoi(val); err == nil {
138+
engine.Global(key, intVal)
139+
} else if boolVar, err := strconv.ParseBool(val); err == nil {
140+
engine.Global(key, boolVar)
141+
} else {
142+
engine.Global(key, val)
143+
}
135144
}
136145
}
137146

0 commit comments

Comments
 (0)