Skip to content

Commit

Permalink
Merge pull request #22 from gruntwork-io/passing-types
Browse files Browse the repository at this point in the history
Fix bug with passing lists and maps to dependencies
  • Loading branch information
brikis98 committed Oct 31, 2016
2 parents 5095907 + 53996f8 commit d0ed81f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
24 changes: 24 additions & 0 deletions examples/dependencies-recursive/boilerplate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,27 @@ dependencies:

- name: Title
description: Enter the title for the dependencies example

- name: java-project
template-folder: ../java-project
output-folder: ./java-project
variables:
- name: CompanyName
description: Enter the name of the company
type: string

- name: ExampleIntConstant
description: Enter the value for an integer constant in the Java file
type: int

- name: IncludeEnum
description: Should we create an example Enum in the Java file?
type: bool

- name: EnumNames
description: Enter the names of the Enums in the Java file
type: list

- name: ExampleMap
description: Enter some example values to store in a HashMap
type: map
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.acme.example

import com.google.common.collect.ImmutableMap;

public class Example {
public static final int EXAMPLE_INT_CONSTANT = 42
public static final Map<> EXAMPLE_MAP = ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3");

public enum ExampleEnum {
Foo, Bar, Baz
}
}
17 changes: 15 additions & 2 deletions test-fixtures/examples-var-files/dependencies-recursive/vars.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
Version: 0.0.3
Title: Recursive dependencies example
WelcomeText: Welcome!
Description: This is a boilerplate template that shows an example of using recursive dependencies

dependencies.Title: Dependencies example
dependencies.Description: This is a boilerplate template that shows an example of using dependencies
dependencies.website.Title: Boilerplate
dependencies.docs.Title: Docs example
WelcomeText: Welcome!
Description: This is a boilerplate template that shows an example of using recursive dependencies

java-project.CompanyName: acme
java-project.ExampleIntConstant: 42
java-project.IncludeEnum: true
java-project.EnumNames:
- Foo
- Bar
- Baz
java-project.ExampleMap:
key1: value1
key2: value2
key3: value3
6 changes: 6 additions & 0 deletions variables/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,16 @@ func UnmarshalValueForVariable(value interface{}, variable Variable) (interface{
if asList, isList := value.([]interface{}); isList {
return util.ToStringList(asList), nil
}
if asList, isList := value.([]string); isList {
return asList, nil
}
case Map:
if asMap, isMap := value.(map[interface{}]interface{}); isMap {
return util.ToStringMap(asMap), nil
}
if asMap, isMap := value.(map[string]string); isMap {
return asMap, nil
}
case Enum:
if asString, isString := value.(string); isString {
for _, option := range variable.Options() {
Expand Down

0 comments on commit d0ed81f

Please sign in to comment.