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

Commit 0d31702

Browse files
kaufersDavid Chung
authored andcommitted
Support int and bool types as template CLI vars (#550)
Signed-off-by: Steven Kaufer <[email protected]>
1 parent fd983ac commit 0d31702

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/cli/services.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/discovery"
@@ -171,7 +172,15 @@ func templateProcessor(plugins func() discovery.Plugins) (*pflag.FlagSet, ToJSON
171172
key := strings.TrimSpace(kv[0])
172173
val := strings.TrimSpace(kv[1])
173174
if key != "" && val != "" {
174-
engine.Global(key, val)
175+
// Attempt to convert to int and bool types so that template operations
176+
// are not only against strings.
177+
if intVal, err := strconv.Atoi(val); err == nil {
178+
engine.Global(key, intVal)
179+
} else if boolVar, err := strconv.ParseBool(val); err == nil {
180+
engine.Global(key, boolVar)
181+
} else {
182+
engine.Global(key, val)
183+
}
175184
}
176185
}
177186

0 commit comments

Comments
 (0)