Run database integrity checks.
(ctx: click.Context)
| 1251 | @cli.command("db-check") |
| 1252 | @click.pass_context |
| 1253 | def db_check_cmd(ctx: click.Context) -> None: |
| 1254 | """Run database integrity checks.""" |
| 1255 | from explainshell.db_check import check as run_db_check |
| 1256 | |
| 1257 | issues = run_db_check(_require_db(ctx, must_exist=True)) |
| 1258 | if not issues: |
| 1259 | click.echo("No issues found.") |
| 1260 | return |
| 1261 | |
| 1262 | n_errors = sum(1 for sev, _ in issues if sev == "error") |
| 1263 | n_warnings = sum(1 for sev, _ in issues if sev == "warning") |
| 1264 | for severity, msg in issues: |
| 1265 | label = ( |
| 1266 | f"{_DB_CHECK_RED}ERROR{_DB_CHECK_RESET}" |
| 1267 | if severity == "error" |
| 1268 | else f"{_DB_CHECK_CYAN}WARNING{_DB_CHECK_RESET}" |
| 1269 | ) |
| 1270 | click.echo(f" {label}: {msg}") |
| 1271 | click.echo(f"\n{n_errors} error(s), {n_warnings} warning(s)") |
| 1272 | if n_errors: |
| 1273 | sys.exit(1) |
| 1274 | |
| 1275 | |
| 1276 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected