MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / runTUIWithOptions

Function runTUIWithOptions

cmd/chief/main.go:356–499  ·  view source on GitHub ↗
(opts *TUIOptions)

Source from the content-addressed store, hash-verified

354}
355
356func runTUIWithOptions(opts *TUIOptions) {
357 provider := resolveProvider(opts.Agent, opts.AgentPath)
358
359 prdPath := opts.PRDPath
360
361 // If no PRD specified, try to find one
362 if prdPath == "" {
363 // Try "main" first
364 mainPath := ".chief/prds/main/prd.md"
365 if _, err := os.Stat(mainPath); err == nil {
366 prdPath = mainPath
367 } else {
368 // Look for any available PRD
369 prdPath = findAvailablePRD()
370 }
371
372 // If still no PRD found, run first-time setup
373 if prdPath == "" {
374 cwd, _ := os.Getwd()
375 showGitignore := git.IsGitRepo(cwd) && !git.IsChiefIgnored(cwd)
376
377 // Run the first-time setup TUI
378 result, err := tui.RunFirstTimeSetup(cwd, showGitignore)
379 if err != nil {
380 fmt.Fprintf(os.Stderr, "Error: %v\n", err)
381 os.Exit(1)
382 }
383
384 if result.Cancelled {
385 return
386 }
387
388 // Save config from setup
389 cfg := config.Default()
390 cfg.OnComplete.Push = result.PushOnComplete
391 cfg.OnComplete.CreatePR = result.CreatePROnComplete
392 if err := config.Save(cwd, cfg); err != nil {
393 fmt.Fprintf(os.Stderr, "Warning: failed to save config: %v\n", err)
394 }
395
396 // Create the PRD
397 newOpts := cmd.NewOptions{
398 Name: result.PRDName,
399 Provider: provider,
400 }
401 if err := cmd.RunNew(newOpts); err != nil {
402 fmt.Fprintf(os.Stderr, "Error: %v\n", err)
403 os.Exit(1)
404 }
405
406 // Restart TUI with the new PRD
407 opts.PRDPath = fmt.Sprintf(".chief/prds/%s/prd.md", result.PRDName)
408 runTUIWithOptions(opts)
409 return
410 }
411 }
412
413 prdDir := filepath.Dir(prdPath)

Callers 1

mainFunction · 0.85

Calls 15

IsGitRepoFunction · 0.92
IsChiefIgnoredFunction · 0.92
RunFirstTimeSetupFunction · 0.92
DefaultFunction · 0.92
SaveFunction · 0.92
RunNewFunction · 0.92
MigrateFromJSONFunction · 0.92
NewAppWithOptionsFunction · 0.92
RunEditFunction · 0.92
resolveProviderFunction · 0.85
findAvailablePRDFunction · 0.85
listAvailablePRDsFunction · 0.85

Tested by

no test coverage detected