Skip to content

Commit f62e00d

Browse files
committed
Replace database clear command
1 parent 92b7061 commit f62e00d

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

src/simdb/cli/commands/database.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/simdb/cli/commands/simulation.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from pathlib import Path
66
from typing import Any, List, Optional, Tuple, Type
77

8+
import appdirs
89
import click
10+
from rich.prompt import Confirm
911

1012
from simdb.cli.manifest import InvalidAlias, Manifest
1113
from simdb.cli.remote_api import RemoteAPI, RemoteError
@@ -114,11 +116,33 @@ def simulation_modify(
114116

115117
@simulation.command("delete")
116118
@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
120140

121141
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+
122146
sim = db.delete_simulation(sim_id)
123147

124148
click.echo(f"Simulation {sim.uuid.hex} deleted.")

0 commit comments

Comments
 (0)