# cli/module.py import argparse from services.git.handler import GitHandler import lib.color_log as color_log def setup_cli(subparsers): git_parser = subparsers.add_parser('git', help='Git operations for Odoo instances') git_subparsers = git_parser.add_subparsers(dest='git_command', help='Git commands') # Clone command clone_parser = git_subparsers.add_parser('clone', help='Clone repository for an instance') clone_parser.add_argument('instance_name', help='Name of the instance to clone repository for') clone_parser.add_argument('--branch', help='Branch to clone (optional)') # Pull command pull_parser = git_subparsers.add_parser('pull', help='Pull updates for an instance') pull_parser.add_argument('instance_name', help='Name of the instance to pull updates for') pull_parser.add_argument('--branch', help='Branch to pull from (optional)') pull_parser.add_argument('--force', action='store_true', help='Force pull with hard reset (discards local changes)') # Get commit command commit_parser = git_subparsers.add_parser('commit', help='Get current commit hash') commit_parser.add_argument('instance_name', help='Name of the instance to get commit for') git_parser.set_defaults(func=git) def git(args): git_handler = GitHandler(config_path="utility/config/settings.yaml") if args.git_command == 'clone': try: success = git_handler.clone_or_open_repo( instance_name=args.instance_name, branch=args.branch ) if success: color_log.Show("OK", f"Successfully cloned repository for {args.instance_name}") else: color_log.Show("FAILED", f"Failed to clone repository for {args.instance_name}") except Exception as e: color_log.Show("FAILED", f"Error cloning repository: {str(e)}") elif args.git_command == 'pull': try: success = git_handler.pull_updates( instance_name=args.instance_name, branch=args.branch, force=args.force ) if success: if args.force: color_log.Show("OK", f"Successfully force pulled updates for {args.instance_name}") else: color_log.Show("OK", f"Successfully pulled updates for {args.instance_name}") else: color_log.Show("FAILED", f"Failed to pull updates for {args.instance_name}") except Exception as e: color_log.Show("FAILED", f"Error pulling updates: {str(e)}") elif args.git_command == 'commit': try: commit_hash = git_handler.get_current_commit() if commit_hash: color_log.Show("INFO", f"Current commit for {args.instance_name}: {commit_hash}") else: color_log.Show("WARNING", f"No commit found for {args.instance_name}") except Exception as e: color_log.Show("FAILED", f"Error getting commit: {str(e)}") else: color_log.Show("ERROR", "Please specify a valid git command (clone/pull/commit)")