MCPcopy Index your code
hub / github.com/go-task/task / promptTaskVars

Method promptTaskVars

requires.go:102–147  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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).
102func (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.
150func getMissingRequiredVars(t *ast.Task) []*ast.VarsWithValidation {

Callers 1

RunTaskMethod · 0.95

Calls 10

canPromptMethod · 0.95
newPrompterMethod · 0.95
IsFunction · 0.92
NewVarsFunction · 0.92
getMissingRequiredVarsFunction · 0.85
getEnumValuesFunction · 0.85
NameMethod · 0.80
GetMethod · 0.45
PromptMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected