MCPcopy Create free account
hub / github.com/driangle/taskmd / buildFromTemplate

Function buildFromTemplate

apps/cli/internal/cli/add.go:186–213  ·  view source on GitHub ↗

buildFromTemplate resolves a template, renders it with variables, and applies CLI flag overrides.

(cmd *cobra.Command, id, title string)

Source from the content-addressed store, hash-verified

184
185// buildFromTemplate resolves a template, renders it with variables, and applies CLI flag overrides.
186func buildFromTemplate(cmd *cobra.Command, id, title string) (string, error) {
187 projectRoot := resolveProjectRoot()
188 userHome, _ := os.UserHomeDir()
189
190 tmpl, ok := template.Resolve(addTemplate, projectRoot, userHome)
191 if !ok {
192 available := template.Discover(projectRoot, userHome)
193 names := make([]string, len(available))
194 for i, t := range available {
195 names[i] = t.Name
196 }
197 return "", fmt.Errorf("template %q not found (available: %s)", addTemplate, strings.Join(names, ", "))
198 }
199
200 vars := map[string]string{
201 "id": id,
202 "title": title,
203 "date": time.Now().Format("2006-01-02"),
204 }
205
206 content := template.RenderTask(tmpl, vars)
207
208 // Apply CLI flag overrides (only for explicitly-set flags)
209 overrides := buildTemplateOverrides(cmd)
210 content = template.ApplyOverrides(content, overrides)
211
212 return content, nil
213}
214
215// buildTemplateOverrides collects frontmatter overrides from explicitly-set CLI flags.
216func buildTemplateOverrides(cmd *cobra.Command) map[string]string {

Callers 1

resolveTaskContentFunction · 0.85

Calls 2

resolveProjectRootFunction · 0.85
buildTemplateOverridesFunction · 0.85

Tested by

no test coverage detected