Skip to content

Commit

Permalink
feat: implement single project truncation command
Browse files Browse the repository at this point in the history
  • Loading branch information
guidodinello committed Dec 17, 2024
1 parent 0006331 commit 35447b8
Showing 1 changed file with 42 additions and 26 deletions.
68 changes: 42 additions & 26 deletions src/claudesync/cli/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,47 +276,63 @@ def ls(config, show_all):
status = " (Archived)" if project.get("archived_at") else ""
click.echo(f" - {project['name']} (ID: {project['id']}){status}")


@project.command()
@click.option(
"-a", "--include-archived", is_flag=True, help="Include archived projects"
)
@click.option("-a", "--include-archived", is_flag=True, help="Include archived projects")
@click.option("--all", "truncate_all", is_flag=True, help="Truncate all projects")
@click.option("-y", "--yes", is_flag=True, help="Skip confirmation prompt")
@click.pass_obj
@handle_errors
def truncate(config, include_archived, yes):
"""Truncate all projects."""
def truncate(config, include_archived, truncate_all, yes):
"""Truncate one or all projects."""
provider = validate_and_get_provider(config)
active_organization_id = config.get("active_organization_id")

projects = provider.get_projects(
active_organization_id, include_archived=include_archived
)
projects = provider.get_projects(active_organization_id, include_archived=include_archived)

if not projects:
click.echo("No projects found.")
return

if not yes:
click.echo("This will delete ALL files from the following projects:")
for project in projects:
status = " (Archived)" if project.get("archived_at") else ""
click.echo(f" - {project['name']} (ID: {project['id']}){status}")
if not click.confirm(
"Are you sure you want to continue? This may take some time."
):
click.echo("Operation cancelled.")
return
if truncate_all:
if not yes:
click.echo("This will delete ALL files from the following projects:")
for project in projects:
status = " (Archived)" if project.get("archived_at") else ""
click.echo(f" - {project['name']} (ID: {project['id']}){status}")
if not click.confirm("Are you sure you want to continue? This may take some time."):
click.echo("Operation cancelled.")
return

with tqdm(total=len(projects), desc="Deleting files from projects") as pbar:
for project in projects:
delete_files_from_project(
provider, active_organization_id, project["id"], project["name"]
)
pbar.update(1)
with tqdm(total=len(projects), desc="Deleting files from projects") as pbar:
for project in projects:
delete_files_from_project(
provider, active_organization_id, project["id"], project["name"]
)
pbar.update(1)

click.echo("All files have been deleted from all projects.")
click.echo("All files have been deleted from all projects.")
return

click.echo("Available projects:")
for idx, project in enumerate(projects, 1):
status = " (Archived)" if project.get("archived_at") else ""
click.echo(f" {idx}. {project['name']} (ID: {project['id']}){status}")

selection = click.prompt("Enter the number of the project to truncate", type=int)
if 1 <= selection <= len(projects):
selected_project = projects[selection - 1]
if yes or click.confirm(
f"Are you sure you want to delete ALL files from project '{selected_project['name']}'?"
):
delete_files_from_project(
provider,
active_organization_id,
selected_project["id"],
selected_project["name"]
)
click.echo(f"All files have been deleted from project '{selected_project['name']}'.")
else:
click.echo("Invalid selection. Please try again.")

@retry_on_403()
def delete_files_from_project(provider, organization_id, project_id, project_name):
Expand Down

0 comments on commit 35447b8

Please sign in to comment.