MCPcopy Index your code
hub / github.com/jetify-com/devbox / run

Function run

internal/setup/setup.go:236–279  ·  view source on GitHub ↗
(ctx context.Context, key string, task Task, prompt string)

Source from the content-addressed store, hash-verified

234}
235
236func run(ctx context.Context, key string, task Task, prompt string) error {
237 ctx = context.WithValue(ctx, ctxKeyTask, key)
238
239 isSudo := isSudo(key)
240 state := loadState(key)
241 if !isSudo && !task.NeedsRun(ctx, state.LastRun) {
242 return nil
243 }
244
245 oldState, newState := state, &state
246 defer func() {
247 if oldState != *newState {
248 saveState(key, *newState)
249 }
250 }()
251
252 if !isSudo && prompt != "" {
253 state.ConfirmPrompt.Message = prompt
254 if state.ConfirmPrompt.Asked && !state.ConfirmPrompt.Allowed {
255 // We've asked before and the user said no.
256 return taskError(key, ErrAlreadyRefused)
257 }
258
259 resp, err := defaultPrompt(prompt)
260 if err != nil {
261 return taskError(key, redact.Errorf("prompt for confirmation: %v", err))
262 }
263 state.ConfirmPrompt.Asked = true
264 state.ConfirmPrompt.Allowed, _ = resp.(bool)
265 if !state.ConfirmPrompt.Allowed {
266 return taskError(key, ErrUserRefused)
267 }
268 }
269
270 state.LastRun = RunInfo{
271 Time: time.Now(),
272 Version: build.Version,
273 }
274 if err := task.Run(ctx); err != nil {
275 state.LastRun.Error = err.Error()
276 return taskError(key, err)
277 }
278 return nil
279}
280
281// Reset removes a task's state so that it acts as if it has never run.
282func Reset(key string) {

Callers 2

RunFunction · 0.70
ConfirmRunFunction · 0.70

Calls 8

ErrorfFunction · 0.92
isSudoFunction · 0.85
loadStateFunction · 0.85
saveStateFunction · 0.85
taskErrorFunction · 0.85
NeedsRunMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected