github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/pkg/alfred/defaults.go (about) 1 package alfred 2 3 import ( 4 "os" 5 ) 6 7 func defaults(task Task, context *Context, tasks map[string]Task) { 8 if len(task.Defaults) == 0 { 9 return 10 } 11 12 if len(task.Defaults) < len(context.Args) { 13 // no need to set defaults, as the args are already set 14 return 15 } 16 17 // ok, so we have some defaults, lets update the context. 18 for idx := len(context.Args); idx < len(task.Defaults); idx++ { 19 // empty? we should bail ... 20 if task.Defaults[idx] == "" || task.Defaults[idx] == " " { 21 outFail("template", "Invalid Argument(s)", context) 22 task.Exit(context, tasks) 23 // if we made it here, then no exit specified, we will exit 24 result(task, context, tasks) 25 os.Exit(42) 26 } 27 // set the defaults 28 context.Args = append(context.Args, translate(task.Defaults[idx], context)) 29 } 30 }