Reset project databases and optionally remove settings.
(
all_: bool = _typer.Option(False, "--all", help="Also remove settings and .gitignore entry"),
force: bool = _typer.Option(False, "-f", "--force", help="Skip confirmation"),
)
| 752 | |
| 753 | @app.command() |
| 754 | def reset( |
| 755 | all_: bool = _typer.Option(False, "--all", help="Also remove settings and .gitignore entry"), |
| 756 | force: bool = _typer.Option(False, "-f", "--force", help="Skip confirmation"), |
| 757 | ) -> None: |
| 758 | """Reset project databases and optionally remove settings.""" |
| 759 | project_root = require_project_root() |
| 760 | cocoindex_dir = project_root / ".cocoindex_code" |
| 761 | db_dir = resolve_db_dir(project_root) |
| 762 | |
| 763 | db_files = [ |
| 764 | cocoindex_db_path(project_root), |
| 765 | target_sqlite_db_path(project_root), |
| 766 | ] |
| 767 | settings_file = project_settings_path(project_root) |
| 768 | |
| 769 | # Determine what will be deleted |
| 770 | to_delete = [f for f in db_files if f.exists()] |
| 771 | if all_: |
| 772 | if settings_file.exists(): |
| 773 | to_delete.append(settings_file) |
| 774 | |
| 775 | if not to_delete and not all_: |
| 776 | _typer.echo("Nothing to reset.") |
| 777 | return |
| 778 | |
| 779 | # Show what will be deleted |
| 780 | if to_delete: |
| 781 | _typer.echo("The following files will be deleted:") |
| 782 | for f in to_delete: |
| 783 | _typer.echo(f" {format_path_for_display(f)}") |
| 784 | |
| 785 | # Confirm |
| 786 | if not force: |
| 787 | if not _typer.confirm("Proceed?"): |
| 788 | _typer.echo("Aborted.") |
| 789 | raise _typer.Exit(code=0) |
| 790 | |
| 791 | # Remove project from daemon first so it releases file handles |
| 792 | try: |
| 793 | from . import client as _client |
| 794 | |
| 795 | _client.remove_project(str(project_root)) |
| 796 | except (ConnectionRefusedError, OSError, RuntimeError): |
| 797 | pass # Daemon not running — that's fine |
| 798 | |
| 799 | # Delete files/directories |
| 800 | import shutil as _shutil |
| 801 | |
| 802 | for f in to_delete: |
| 803 | if f.is_dir(): |
| 804 | _shutil.rmtree(f) |
| 805 | else: |
| 806 | f.unlink(missing_ok=True) |
| 807 | |
| 808 | if all_: |
| 809 | # Remove db_dir if empty and different from cocoindex_dir |
| 810 | if db_dir != cocoindex_dir: |
| 811 | try: |
nothing calls this directly
no test coverage detected