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

Method RunTask

task.go:128–299  ·  view source on GitHub ↗

RunTask runs a task by its name

(ctx context.Context, call *Call)

Source from the content-addressed store, hash-verified

126
127// RunTask runs a task by its name
128func (e *Executor) RunTask(ctx context.Context, call *Call) error {
129 // Inject prompted vars into call if available
130 if e.promptedVars != nil {
131 if call.Vars == nil {
132 call.Vars = ast.NewVars()
133 }
134 for name, v := range e.promptedVars.All() {
135 // Only inject if not already set in call
136 if _, ok := call.Vars.Get(name); !ok {
137 call.Vars.Set(name, v)
138 }
139 }
140 }
141
142 t, err := e.FastCompiledTask(call)
143 if err != nil {
144 return err
145 }
146 if !shouldRunOnCurrentPlatform(t.Platforms) {
147 e.Logger.VerboseOutf(logger.Yellow, `task: %q not for current platform - ignored\n`, call.Task)
148 return nil
149 }
150
151 // Check required vars early (before template compilation) if we can't prompt.
152 // This gives a clear "missing required variables" error instead of a template error.
153 if !e.canPrompt() {
154 if err := e.areTaskRequiredVarsSet(t); err != nil {
155 return err
156 }
157 }
158
159 t, err = e.CompiledTask(call)
160 if err != nil {
161 return err
162 }
163
164 // Check if condition after CompiledTask so dynamic variables are resolved
165 if strings.TrimSpace(t.If) != "" {
166 if err := execext.RunCommand(ctx, &execext.RunCommandOptions{
167 Command: t.If,
168 Dir: t.Dir,
169 Env: env.Get(t),
170 }); err != nil {
171 e.Logger.VerboseOutf(logger.Yellow, "task: if condition not met - skipped: %q\n", call.Task)
172 return nil
173 }
174 }
175
176 // Prompt for missing required vars after if check (avoid prompting if task won't run)
177 prompted, err := e.promptTaskVars(t, call)
178 if err != nil {
179 return err
180 }
181 if prompted {
182 // Recompile with the new vars
183 t, err = e.FastCompiledTask(call)
184 if err != nil {
185 return err

Callers 4

watchTasksMethod · 0.95
RunMethod · 0.95
runDepsMethod · 0.95
runCommandMethod · 0.95

Calls 15

FastCompiledTaskMethod · 0.95
canPromptMethod · 0.95
CompiledTaskMethod · 0.95
promptTaskVarsMethod · 0.95
startExecutionMethod · 0.95
runDepsMethod · 0.95
mkdirMethod · 0.95
runDeferredMethod · 0.95

Tested by

no test coverage detected