Run the `clear` subcommand.
(clear_type: _CLEAR_CHOICE)
| 135 | |
| 136 | |
| 137 | def _run_clear(clear_type: _CLEAR_CHOICE) -> None: |
| 138 | """Run the `clear` subcommand.""" |
| 139 | cache_folder = resolve_cache_folder() |
| 140 | if clear_type == "index" or clear_type == "all": |
| 141 | indexes = [] |
| 142 | for path in cache_folder.glob("*/index"): |
| 143 | if not _SHA_256_REGEX.match(path.parent.name): |
| 144 | continue |
| 145 | if PersistencePath.from_path(path).non_existing(): |
| 146 | continue |
| 147 | indexes.append(path) |
| 148 | |
| 149 | if not indexes: |
| 150 | print(f"No indexes found to clear in `{cache_folder}`") |
| 151 | else: |
| 152 | for path in indexes: |
| 153 | index_folder = path.parent |
| 154 | rmtree(index_folder) |
| 155 | print(f"Cleared index at `{index_folder}`") |
| 156 | |
| 157 | if clear_type == "savings" or clear_type == "all": |
| 158 | path = cache_folder / "savings.jsonl" |
| 159 | if not path.exists(): |
| 160 | print(f"No savings file found at `{path}`") |
| 161 | else: |
| 162 | path.unlink() |
| 163 | print(f"Cleared savings at `{path}`") |
| 164 | |
| 165 | |
| 166 | def _cli_main() -> None: |