(options: RunDoctorOptions = {})
| 975 | } |
| 976 | |
| 977 | export async function runDoctor(options: RunDoctorOptions = {}): Promise<number> { |
| 978 | const deps = depsFrom(options); |
| 979 | const prompts = options.prompts ?? deps.prompts; |
| 980 | const cwd = options.cwd ?? process.cwd(); |
| 981 | |
| 982 | if (options.help) { |
| 983 | printDoctorHelp(); |
| 984 | return 0; |
| 985 | } |
| 986 | |
| 987 | const configMigrationWarnings = migrateConfigLocationsForCli(cwd, prompts.log); |
| 988 | |
| 989 | if (options.issue) { |
| 990 | return runIssueFlow({ cwd, prompts, deps }); |
| 991 | } |
| 992 | |
| 993 | const v22Result = await runV22BackfillCommands( |
| 994 | { |
| 995 | name: "Pi", |
| 996 | openDatabase: deps.openDatabase, |
| 997 | closeDatabase: deps.closeDatabase, |
| 998 | log: prompts.log, |
| 999 | }, |
| 1000 | options, |
| 1001 | ); |
| 1002 | if (v22Result.handled) { |
| 1003 | return v22Result.exitCode; |
| 1004 | } |
| 1005 | |
| 1006 | prompts.intro("Magic Context for Pi Doctor"); |
| 1007 | const first = await runHealthChecks({ |
| 1008 | cwd, |
| 1009 | prompts, |
| 1010 | deps, |
| 1011 | configMigrationWarnings, |
| 1012 | }); |
| 1013 | console.log(""); |
| 1014 | prompts.log.message(`Summary: PASS ${first.pass} / WARN ${first.warn} / FAIL ${first.fail}`); |
| 1015 | |
| 1016 | if (options.force) { |
| 1017 | const fixed = repair(first.repairPlan, prompts); |
| 1018 | console.log(""); |
| 1019 | prompts.log.message( |
| 1020 | `Repair attempted; ${fixed} item(s) changed. Re-running health checks.`, |
| 1021 | ); |
| 1022 | const second = await runHealthChecks({ |
| 1023 | cwd, |
| 1024 | prompts, |
| 1025 | deps, |
| 1026 | configMigrationWarnings, |
| 1027 | }); |
| 1028 | console.log(""); |
| 1029 | prompts.log.message( |
| 1030 | `Summary: PASS ${second.pass} / WARN ${second.warn} / FAIL ${second.fail}`, |
| 1031 | ); |
| 1032 | prompts.outro( |
| 1033 | second.fail > 0 ? "Doctor found failures after repair" : "Doctor repair complete", |
| 1034 | ); |
no test coverage detected