Coverage for scripts / delete_organization.py: 0%
37 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-25 18:08 -0500
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-25 18:08 -0500
1#!/usr/bin/env python3
2"""
3Delete a JSM organization.
5Usage:
6 python delete_organization.py 12345 --yes
7 python delete_organization.py 12345 --dry-run
8"""
10import sys
11import os
12import argparse
13from pathlib import Path
15sys.path.insert(0, str(Path(__file__).parent.parent.parent / 'shared' / 'scripts' / 'lib'))
17from config_manager import get_jira_client
18from error_handler import print_error, JiraError
19from formatters import print_success
22def delete_organization_func(organization_id: int, profile: str = None) -> None:
23 """
24 Delete an organization.
26 Args:
27 organization_id: Organization ID
28 profile: JIRA profile to use
29 """
30 with get_jira_client(profile) as client:
31 client.delete_organization(organization_id)
34def main():
35 """Main entry point."""
36 parser = argparse.ArgumentParser(
37 description='Delete a JSM organization',
38 formatter_class=argparse.RawDescriptionHelpFormatter,
39 epilog="""
40Examples:
41 Delete organization (with confirmation skip):
42 %(prog)s 12345 --yes
44 Dry-run:
45 %(prog)s 12345 --dry-run
46 """
47 )
49 parser.add_argument('organization_id', type=int,
50 help='Organization ID')
51 parser.add_argument('--yes', '-y', action='store_true',
52 help='Skip confirmation prompt')
53 parser.add_argument('--dry-run', action='store_true',
54 help='Show what would be deleted without deleting')
55 parser.add_argument('--profile',
56 help='JIRA profile to use from config')
58 args = parser.parse_args()
60 try:
61 if args.dry_run:
62 print("DRY RUN MODE - No changes will be made\n")
63 print(f"Would delete organization {args.organization_id}")
64 return 0
66 if not args.yes:
67 print_error("Confirmation required. Use --yes flag to confirm deletion.")
68 return 1
70 delete_organization_func(
71 organization_id=args.organization_id,
72 profile=args.profile
73 )
75 print_success(f"Successfully deleted organization {args.organization_id}")
77 return 0
79 except JiraError as e:
80 print_error(f"Failed to delete organization: {e}")
81 return 1
82 except Exception as e:
83 print_error(f"Unexpected error: {e}")
84 return 1
87if __name__ == '__main__':
88 sys.exit(main())