Main entry point for the CLI.
()
| 506 | |
| 507 | |
| 508 | def main(): |
| 509 | """Main entry point for the CLI.""" |
| 510 | try: |
| 511 | parser = argparse.ArgumentParser(description='DevOps Agent CLI') |
| 512 | parser.add_argument('--debug', action='store_true', help='Enable debug logging') |
| 513 | |
| 514 | # Create subparsers for different command groups |
| 515 | subparsers = parser.add_subparsers(dest='command', help='Command group') |
| 516 | |
| 517 | # Set up command parsers |
| 518 | setup_ec2_parser(subparsers) |
| 519 | setup_github_parser(subparsers) |
| 520 | setup_deploy_parser(subparsers) |
| 521 | |
| 522 | # Parse arguments |
| 523 | args = parser.parse_args() |
| 524 | |
| 525 | # Set up logging |
| 526 | if args.debug: |
| 527 | logging.getLogger().setLevel(logging.DEBUG) |
| 528 | |
| 529 | # Exit if no command specified |
| 530 | if not args.command: |
| 531 | parser.print_help() |
| 532 | sys.exit(1) |
| 533 | |
| 534 | # Handle commands |
| 535 | if args.command == 'ec2': |
| 536 | if not args.ec2_command: |
| 537 | parser.parse_args(['ec2', '--help']) |
| 538 | sys.exit(1) |
| 539 | sys.exit(handle_ec2_command(args)) |
| 540 | |
| 541 | elif args.command == 'github': |
| 542 | if not args.github_command: |
| 543 | parser.parse_args(['github', '--help']) |
| 544 | sys.exit(1) |
| 545 | sys.exit(handle_github_command(args)) |
| 546 | |
| 547 | elif args.command == 'deploy': |
| 548 | if not args.deploy_command: |
| 549 | parser.parse_args(['deploy', '--help']) |
| 550 | sys.exit(1) |
| 551 | sys.exit(handle_deploy_command(args)) |
| 552 | |
| 553 | sys.exit(0) |
| 554 | |
| 555 | except KeyboardInterrupt: |
| 556 | print("\nOperation cancelled by user") |
| 557 | sys.exit(130) # Standard exit code for SIGINT |
| 558 | except Exception as e: |
| 559 | print_error("Unexpected error", f"Error: {e}") |
| 560 | if args and args.debug: |
| 561 | import traceback |
| 562 | traceback.print_exc() |
| 563 | sys.exit(1) |
| 564 | |
| 565 |