-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_all_workspaces.py
More file actions
55 lines (41 loc) · 1.65 KB
/
delete_all_workspaces.py
File metadata and controls
55 lines (41 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import argparse
import asyncio
from codesphere import CodesphereSDK
async def delete_all_workspaces(team_id: int, dry_run: bool = False) -> None:
async with CodesphereSDK() as sdk:
print(f"Fetching workspaces for team {team_id}...")
workspaces = await sdk.workspaces.list(team_id=team_id)
if not workspaces:
print("No workspaces found in this team.")
return
print(f"Found {len(workspaces)} workspace(s):\n")
for ws in workspaces:
print(f" • {ws.name} (ID: {ws.id})")
if dry_run:
print("\n[DRY RUN] No workspaces were deleted.")
return
print("\n" + "=" * 50)
confirm = input(f"Delete all {len(workspaces)} workspaces? (yes/no): ")
if confirm.lower() != "yes":
print("Aborted.")
return
print("\nDeleting workspaces...")
for ws in workspaces:
try:
await ws.delete()
print(f" ✓ Deleted: {ws.name} (ID: {ws.id})")
except Exception as e:
print(f" ✗ Failed to delete {ws.name}: {e}")
print(f"\n✓ Done. Deleted {len(workspaces)} workspace(s).")
def main():
parser = argparse.ArgumentParser(description="Delete all workspaces in a team")
parser.add_argument("--team-id", type=int, required=True, help="Team ID")
parser.add_argument(
"--dry-run",
action="store_true",
help="Show what would be deleted without actually deleting",
)
args = parser.parse_args()
asyncio.run(delete_all_workspaces(team_id=args.team_id, dry_run=args.dry_run))
if __name__ == "__main__":
main()