@@ -21,15 +21,15 @@ type TemplateUserCommand interface {
2121 Vars () string
2222}
2323
24- func ConvertTemplateToMap (tuc TemplateUserCommand ) (map [string ]interface {}, error ) {
24+ func ConvertTemplateToMap (templateUserCommand TemplateUserCommand ) (map [string ]interface {}, error ) {
2525 // Read the template file
26- content , err := fileutils .ReadFile (tuc .TemplatePath ())
26+ content , err := fileutils .ReadFile (templateUserCommand .TemplatePath ())
2727 if errorutils .CheckError (err ) != nil {
2828 return nil , err
2929 }
3030 // Replace vars string-by-string if needed
31- if len (tuc .Vars ()) > 0 {
32- templateVars := coreutils .SpecVarsStringToMap (tuc .Vars ())
31+ if len (templateUserCommand .Vars ()) > 0 {
32+ templateVars := coreutils .SpecVarsStringToMap (templateUserCommand .Vars ())
3333 content = coreutils .ReplaceVars (content , templateVars )
3434 }
3535 // Unmarshal template to a map
@@ -38,6 +38,36 @@ func ConvertTemplateToMap(tuc TemplateUserCommand) (map[string]interface{}, erro
3838 return configMap , errorutils .CheckError (err )
3939}
4040
41+ func ConvertTemplateToMaps (templateUserCommand TemplateUserCommand ) (interface {}, error ) {
42+ content , err := fileutils .ReadFile (templateUserCommand .TemplatePath ())
43+ if err != nil {
44+ return nil , errorutils .CheckError (err )
45+ }
46+ // Replace vars string-by-string if needed
47+ if len (templateUserCommand .Vars ()) > 0 {
48+ templateVars := coreutils .SpecVarsStringToMap (templateUserCommand .Vars ())
49+ content = coreutils .ReplaceVars (content , templateVars )
50+ }
51+
52+ var multiRepoCreateEntities []map [string ]interface {}
53+ err = json .Unmarshal (content , & multiRepoCreateEntities )
54+ if err == nil {
55+ return multiRepoCreateEntities , nil
56+ }
57+
58+ if _ , ok := err .(* json.SyntaxError ); ok {
59+ return nil , errorutils .CheckError (err )
60+ }
61+
62+ var repoCreateEntity map [string ]interface {}
63+ err = json .Unmarshal (content , & repoCreateEntity )
64+ if err == nil {
65+ return repoCreateEntity , nil
66+ }
67+
68+ return nil , errorutils .CheckError (err )
69+ }
70+
4171func ValidateMapEntry (key string , value interface {}, writersMap map [string ]ioutils.AnswerWriter ) error {
4272 if _ , ok := writersMap [key ]; ! ok {
4373 return errorutils .CheckErrorf ("template syntax error: unknown key: \" " + key + "\" ." )
0 commit comments