Add delete-run and delete-cache commands

- delete-run: Delete a run by ID (with confirmation unless -f)
- delete-cache: Delete a cached item by hash (with confirmation unless -f)
- Both require login

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gilesb
2026-01-08 02:03:29 +00:00
parent 147457d913
commit 2cba9c3ba6

View File

@@ -293,6 +293,95 @@ def status(run_id):
click.echo(f"Error: {run['error']}")
@cli.command("delete-run")
@click.argument("run_id")
@click.option("--force", "-f", is_flag=True, help="Skip confirmation")
def delete_run(run_id, force):
"""Delete a run. Requires login.
RUN_ID: The run ID to delete
"""
token_data = load_token()
if not token_data.get("access_token"):
click.echo("Not logged in. Please run: artdag login <username>", err=True)
sys.exit(1)
# Get run info first
try:
run = api_get(f"/runs/{run_id}")
except requests.HTTPError as e:
if e.response.status_code == 404:
click.echo(f"Run not found: {run_id}", err=True)
sys.exit(1)
raise
if not force:
click.echo(f"Run: {run_id}")
click.echo(f"Status: {run['status']}")
click.echo(f"Recipe: {run['recipe']}")
if not click.confirm("Delete this run?"):
click.echo("Cancelled.")
return
try:
headers = {"Authorization": f"Bearer {token_data['access_token']}"}
resp = requests.delete(f"{get_server()}/runs/{run_id}", headers=headers)
if resp.status_code == 400:
click.echo(f"Cannot delete: {resp.json().get('detail', 'Unknown error')}", err=True)
sys.exit(1)
if resp.status_code == 403:
click.echo("Access denied", err=True)
sys.exit(1)
if resp.status_code == 404:
click.echo(f"Run not found: {run_id}", err=True)
sys.exit(1)
resp.raise_for_status()
except requests.RequestException as e:
click.echo(f"Failed to delete run: {e}", err=True)
sys.exit(1)
click.echo(f"Deleted run: {run_id}")
@cli.command("delete-cache")
@click.argument("content_hash")
@click.option("--force", "-f", is_flag=True, help="Skip confirmation")
def delete_cache(content_hash, force):
"""Delete a cached item. Requires login.
CONTENT_HASH: The content hash to delete
"""
token_data = load_token()
if not token_data.get("access_token"):
click.echo("Not logged in. Please run: artdag login <username>", err=True)
sys.exit(1)
if not force:
click.echo(f"Content hash: {content_hash}")
if not click.confirm("Delete this cached item?"):
click.echo("Cancelled.")
return
try:
headers = {"Authorization": f"Bearer {token_data['access_token']}"}
resp = requests.delete(f"{get_server()}/cache/{content_hash}", headers=headers)
if resp.status_code == 400:
click.echo(f"Cannot delete: {resp.json().get('detail', 'Unknown error')}", err=True)
sys.exit(1)
if resp.status_code == 403:
click.echo("Access denied", err=True)
sys.exit(1)
if resp.status_code == 404:
click.echo(f"Content not found: {content_hash}", err=True)
sys.exit(1)
resp.raise_for_status()
except requests.RequestException as e:
click.echo(f"Failed to delete cache item: {e}", err=True)
sys.exit(1)
click.echo(f"Deleted: {content_hash}")
@cli.command()
@click.option("--limit", "-l", default=20, help="Max items to show")
def cache(limit):