promptTaskVars prompts for any missing required vars from a single task. Used for sequential task calls (cmds) where we can prompt just-in-time. Returns true if any vars were prompted (caller should recompile the task).
(t *ast.Task, call *Call)
| 100 | // Used for sequential task calls (cmds) where we can prompt just-in-time. |
| 101 | // Returns true if any vars were prompted (caller should recompile the task). |
| 102 | func (e *Executor) promptTaskVars(t *ast.Task, call *Call) (bool, error) { |
| 103 | if !e.canPrompt() || t.Requires == nil || len(t.Requires.Vars) == 0 { |
| 104 | return false, nil |
| 105 | } |
| 106 | |
| 107 | // Find missing vars, excluding already prompted ones |
| 108 | var missing []*ast.VarsWithValidation |
| 109 | for _, v := range getMissingRequiredVars(t) { |
| 110 | if e.promptedVars != nil { |
| 111 | if _, ok := e.promptedVars.Get(v.Name); ok { |
| 112 | continue |
| 113 | } |
| 114 | } |
| 115 | missing = append(missing, v) |
| 116 | } |
| 117 | |
| 118 | if len(missing) == 0 { |
| 119 | return false, nil |
| 120 | } |
| 121 | |
| 122 | prompter := e.newPrompter() |
| 123 | |
| 124 | for _, v := range missing { |
| 125 | value, err := prompter.Prompt(v.Name, getEnumValues(v.Enum)) |
| 126 | if err != nil { |
| 127 | if errors.Is(err, input.ErrCancelled) { |
| 128 | return false, &errors.TaskCancelledByUserError{TaskName: t.Name()} |
| 129 | } |
| 130 | return false, err |
| 131 | } |
| 132 | |
| 133 | // Add to call.Vars for recompilation |
| 134 | if call.Vars == nil { |
| 135 | call.Vars = ast.NewVars() |
| 136 | } |
| 137 | call.Vars.Set(v.Name, ast.Var{Value: value}) |
| 138 | |
| 139 | // Cache for reuse by other tasks |
| 140 | if e.promptedVars == nil { |
| 141 | e.promptedVars = ast.NewVars() |
| 142 | } |
| 143 | e.promptedVars.Set(v.Name, ast.Var{Value: value}) |
| 144 | } |
| 145 | |
| 146 | return true, nil |
| 147 | } |
| 148 | |
| 149 | // getMissingRequiredVars returns required vars that are not set in the task's vars. |
| 150 | func getMissingRequiredVars(t *ast.Task) []*ast.VarsWithValidation { |
no test coverage detected