From f09f31c6d55dd15a4db5e5c675518b4307b72b9b Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Sun, 25 Jan 2026 20:39:01 +0100 Subject: [PATCH] fix: skip prompting for vars when task if condition fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the prompt for required variables AFTER the if condition check. This avoids asking the user for input when the task won't run anyway. The order in RunTask() is now: 1. FastCompiledTask 2. Check required vars early (non-interactive mode only) 3. CompiledTask (resolve dynamic vars) 4. Check if condition → exit early if false 5. Prompt for missing vars (only if task will run) 6. Validate required vars --- task.go | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/task.go b/task.go index 5456115f..54cda927 100644 --- a/task.go +++ b/task.go @@ -148,7 +148,32 @@ func (e *Executor) RunTask(ctx context.Context, call *Call) error { return nil } - // Prompt for missing required vars (just-in-time for sequential task calls) + // Check required vars early (before template compilation) if we can't prompt. + // This gives a clear "missing required variables" error instead of a template error. + if !e.canPrompt() { + if err := e.areTaskRequiredVarsSet(t); err != nil { + return err + } + } + + t, err = e.CompiledTask(call) + if err != nil { + return err + } + + // Check if condition after CompiledTask so dynamic variables are resolved + if strings.TrimSpace(t.If) != "" { + if err := execext.RunCommand(ctx, &execext.RunCommandOptions{ + Command: t.If, + Dir: t.Dir, + Env: env.Get(t), + }); err != nil { + e.Logger.VerboseOutf(logger.Yellow, "task: if condition not met - skipped: %q\n", call.Task) + return nil + } + } + + // Prompt for missing required vars after if check (avoid prompting if task won't run) prompted, err := e.promptTaskVars(t, call) if err != nil { return err @@ -165,27 +190,10 @@ func (e *Executor) RunTask(ctx context.Context, call *Call) error { return err } - t, err = e.CompiledTask(call) - if err != nil { - return err - } - if err := e.areTaskRequiredVarsAllowedValuesSet(t); err != nil { return err } - // Check if condition after CompiledTask so dynamic variables are resolved - if strings.TrimSpace(t.If) != "" { - if err := execext.RunCommand(ctx, &execext.RunCommandOptions{ - Command: t.If, - Dir: t.Dir, - Env: env.Get(t), - }); err != nil { - e.Logger.VerboseOutf(logger.Yellow, "task: if condition not met - skipped: %q\n", call.Task) - return nil - } - } - if !e.Watch && atomic.AddInt32(e.taskCallCount[t.Task], 1) >= MaximumTaskCall { return &errors.TaskCalledTooManyTimesError{ TaskName: t.Task,