github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/pkg/alfred/for.go (about) 1 package alfred 2 3 import ( 4 "strings" 5 ) 6 7 func forC(task Task, context *Context, tasks map[string]Task) { 8 if task.For.Args == "" { 9 return 10 } 11 12 if task.For.Tasks == "" && task.For.MultiTask == "" { 13 // probably a typo ... lets error out 14 outFail("for", "'args' set but missing 'tasks' or 'multitask'", context) 15 task.Exit(context, tasks) 16 return 17 } 18 19 dir, _ := task.dir(context) 20 // alright, lets figure out our new lines 21 args := strings.Split(strings.TrimSpace(evaluate(translate(task.For.Args, context), dir)), "\n") 22 tg := make([]TaskGroup, 0) 23 // if our tasks list isn't empty, lets loop through it 24 if task.For.Tasks != "" { 25 // parse our task group(should only be space separated ...) 26 tgs := task.ParseTaskGroup(translate(task.For.Tasks, context)) 27 for _, taskGroup := range tgs { 28 // loop through each of our arguments 29 for _, arg := range args { 30 // append the taskname and the argument 31 tg = append(tg, TaskGroup{ 32 Name: translate(taskGroup.Name, context), 33 Args: []string{translate(arg, context)}, 34 }) 35 } 36 } 37 // now, we have all our tasks, lets run them as a task group 38 execTaskGroup(tg, task, context, tasks) 39 } 40 41 tg = make([]TaskGroup, 0) 42 // if our tasks list isn't empty, lets loop through it 43 if task.For.MultiTask != "" { 44 // parse our task group(should only be space separated ...) 45 tgs := task.ParseTaskGroup(translate(task.For.MultiTask, context)) 46 for _, taskGroup := range tgs { 47 // loop through each of our arguments 48 for _, arg := range args { 49 // append the taskname and the argument 50 tg = append(tg, TaskGroup{ 51 Name: translate(taskGroup.Name, context), 52 Args: []string{translate(arg, context)}, 53 }) 54 } 55 } 56 // now, we have all our tasks, lets run them as a task group 57 goExecTaskGroup(tg, task, context, tasks) 58 } 59 }