Skip to content
Snippets Groups Projects
Commit 7b973fcc authored by Tamer Tas's avatar Tamer Tas
Browse files

Implement conditional contexts

Fixes #5
parent 80981ed7
No related branches found
No related tags found
No related merge requests found
......@@ -110,6 +110,36 @@ func (t *dirTemplate) UseDefaultValues() {
func (t *dirTemplate) BindPrompts() {
for s, v := range t.Context {
if m, ok := v.(map[string]interface{}); ok {
advancedMode := prompt.New(s, false)
for k, v2 := range m {
if t.ShouldUseDefaults {
t.FuncMap[k] = func() interface{} {
switch v2 := v2.(type) {
// First is the default value if it's a slice
case []interface{}:
return v2[0]
}
return v2
}
} else {
v, p := v2, prompt.New(k, v2)
t.FuncMap[k] = func() interface{} {
if val := advancedMode().(bool); val {
return p()
}
return v
}
}
}
continue
}
if t.ShouldUseDefaults {
t.FuncMap[s] = func() interface{} {
switch v := v.(type) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment