MCPcopy Index your code
hub / github.com/commitdev/zero / executeTemplates

Function executeTemplates

internal/generate/generate_modules.go:161–209  ·  view source on GitHub ↗
(templates []*fileConfig, data interface{}, delimiters []string)

Source from the content-addressed store, hash-verified

159}
160
161func executeTemplates(templates []*fileConfig, data interface{}, delimiters []string) {
162 var wg sync.WaitGroup
163 leftDelim := delimiters[0]
164 rightDelim := delimiters[1]
165 if leftDelim == "" {
166 leftDelim = "{{"
167 }
168 if rightDelim == "" {
169 rightDelim = "}}"
170 }
171 // flog.Infof("Templating params:")
172 // pp.Println(data)
173
174 for _, tmpltConfig := range templates {
175 source := tmpltConfig.source
176 dest := tmpltConfig.destination
177
178 outputDirPath, _ := path.Split(dest)
179 err := fs.CreateDirs(outputDirPath)
180 if err != nil {
181 flog.Errorf("Error creating directory '%s': %v", source, err)
182 }
183 f, err := os.Create(dest)
184 if err != nil {
185 flog.Errorf("Error initializing file '%s'", err)
186 }
187
188 err = f.Chmod(tmpltConfig.modeBits)
189 if err != nil {
190 flog.Errorf("Error changing mode bits '%s'", err)
191 }
192
193 // @TODO if strict mode then only copy file
194 name := path.Base(source)
195 template, err := template.New(name).Delims(leftDelim, rightDelim).Funcs(util.FuncMap).ParseFiles(source)
196 if err != nil {
197 flog.Errorf("Error in template '%s': %v", source, err)
198 }
199 err = template.Execute(f, data)
200
201 if err != nil {
202 flog.Errorf("Error templating '%s': %v", source, err)
203 } else {
204 flog.Successf("Finished templating : %s", dest)
205 }
206 }
207
208 wg.Wait()
209}
210
211func copyBinFiles(binTypeFiles []*fileConfig) {
212 for _, binFile := range binTypeFiles {

Callers 1

GenerateFunction · 0.85

Calls 3

CreateDirsFunction · 0.92
ErrorfFunction · 0.92
SuccessfFunction · 0.92

Tested by

no test coverage detected