MCPcopy
hub / github.com/go-task/task / itemsFromFor

Function itemsFromFor

variables.go:357–448  ·  view source on GitHub ↗
(
	f *ast.For,
	dir string,
	sources []*ast.Glob,
	generates []*ast.Glob,
	gitignore bool,
	vars *ast.Vars,
	location *ast.Location,
	cache *templater.Cache,
)

Source from the content-addressed store, hash-verified

355}
356
357func itemsFromFor(
358 f *ast.For,
359 dir string,
360 sources []*ast.Glob,
361 generates []*ast.Glob,
362 gitignore bool,
363 vars *ast.Vars,
364 location *ast.Location,
365 cache *templater.Cache,
366) ([]any, []string, error) {
367 var keys []string // The list of keys to loop over (only if looping over a map)
368 var values []any // The list of values to loop over
369 // Get the list from a matrix
370 if f.Matrix.Len() != 0 {
371 resolvedMatrix, err := resolveMatrixRefs(f.Matrix, cache)
372 if err != nil {
373 return nil, nil, errors.TaskfileInvalidError{
374 URI: location.Taskfile,
375 Err: err,
376 }
377 }
378 return asAnySlice(product(resolvedMatrix)), nil, nil
379 }
380 // Get the list from the explicit for list
381 if len(f.List) > 0 {
382 return f.List, nil, nil
383 }
384 // Get the list from the task sources
385 if f.From == "sources" {
386 glist, err := fingerprint.Globs(dir, sources, gitignore)
387 if err != nil {
388 return nil, nil, err
389 }
390 // Make the paths relative to the task dir
391 for i, v := range glist {
392 if glist[i], err = filepath.Rel(dir, v); err != nil {
393 return nil, nil, err
394 }
395 }
396 values = asAnySlice(glist)
397 }
398 // Get the list from the task generates
399 if f.From == "generates" {
400 glist, err := fingerprint.Globs(dir, generates, gitignore)
401 if err != nil {
402 return nil, nil, err
403 }
404 // Make the paths relative to the task dir
405 for i, v := range glist {
406 if glist[i], err = filepath.Rel(dir, v); err != nil {
407 return nil, nil, err
408 }
409 }
410 values = asAnySlice(glist)
411 }
412 // Get the list from a variable and split it up
413 if f.Var != "" {
414 if vars != nil {

Callers 1

compiledTaskMethod · 0.85

Calls 7

GlobsFunction · 0.92
NewFunction · 0.92
resolveMatrixRefsFunction · 0.85
asAnySliceFunction · 0.85
productFunction · 0.85
LenMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…