|
5 | 5 | from pathlib import Path |
6 | 6 | from typing import Any, List, Optional, Tuple, Type |
7 | 7 |
|
| 8 | +import appdirs |
8 | 9 | import click |
| 10 | +from rich.prompt import Confirm |
9 | 11 |
|
10 | 12 | from simdb.cli.manifest import InvalidAlias, Manifest |
11 | 13 | from simdb.cli.remote_api import RemoteAPI, RemoteError |
@@ -114,11 +116,33 @@ def simulation_modify( |
114 | 116 |
|
115 | 117 | @simulation.command("delete") |
116 | 118 | @pass_config |
117 | | -@click.argument("sim_id") |
118 | | -def simulation_delete(config: Config, sim_id: str): |
119 | | - """Delete the ingested simulation with given SIM_ID (UUID or alias).""" |
| 119 | +@click.argument("sim_id", required=False) |
| 120 | +@click.option( |
| 121 | + "--all", |
| 122 | + "delete_all", |
| 123 | + is_flag=True, |
| 124 | + help="Reset the local database, deleting all simulations.", |
| 125 | +) |
| 126 | +def simulation_delete(config: Config, sim_id: Optional[str], delete_all: bool): |
| 127 | + """Delete the ingested simulation with given SIM_ID (UUID or alias). |
| 128 | +
|
| 129 | + Use --all to reset the local database and delete all simulations.""" |
| 130 | + if delete_all and Confirm.ask( |
| 131 | + "This will delete all locally stored simulation entries, are you sure?" |
| 132 | + ): |
| 133 | + db_file = Path( |
| 134 | + config.get_string_option("db.file", default=None) |
| 135 | + or f"{appdirs.user_data_dir('simdb')}/sim.db" |
| 136 | + ) |
| 137 | + db_file.unlink(missing_ok=True) |
| 138 | + click.echo("Local database reset.") |
| 139 | + return |
120 | 140 |
|
121 | 141 | db = get_local_db(config) |
| 142 | + |
| 143 | + if sim_id is None: |
| 144 | + raise click.ClickException("Either SIM_ID or --all must be provided.") |
| 145 | + |
122 | 146 | sim = db.delete_simulation(sim_id) |
123 | 147 |
|
124 | 148 | click.echo(f"Simulation {sim.uuid.hex} deleted.") |
|
0 commit comments