#!/usr/bin/env python3 import locale from argparse import Namespace, ArgumentParser from git_flow import GitFlowError from git_flow.command.base import Command from git_flow.command.branch import BranchCommand from git_flow.command.commit import CommitCommand from git_flow.command.init import InitCommand from git_flow.command.merge import MergeCommand from git_flow.command.new import NewCommand from git_flow.command.release import ReleaseCommand from git_flow.command.tag import TagCommand from git_flow.io import * REPOSITORY_TOKEN_PATH = ".repository-token" LOCALE = "es_AR.UTF-8" class GitFlowCommand(Command): commands: tuple[Command, ...] def __init__(self, *args: Command) -> None: self.commands = args def name(self) -> str: return "git-flow" def description(self) -> str: return """Git flow es una herramienta para automatizar un workflow siguiendo conventional commits, conventional branch y semver.""" def setup_parser(self, parser: ArgumentParser) -> ArgumentParser: subparsers = parser.add_subparsers( title="comandos", dest="command", required=True ) for command in self.commands: subparser = subparsers.add_parser( command.name(), description=command.description() ) command.setup_parser(subparser) return parser def get_parser(self) -> ArgumentParser: parser = ArgumentParser(self.name(), description=self.description()) return self.setup_parser(parser) def run(self, args: Namespace = Namespace()): args = self.get_parser().parse_args() for command in self.commands: if command.name() == args.command: command.init() return command.run(args) def main(): try: locale.setlocale(locale.LC_ALL, LOCALE) except locale.Error as e: print_warning(f"No se pudo configurar el locale '{LOCALE}': {e}") command = GitFlowCommand( InitCommand(), NewCommand(), CommitCommand(), MergeCommand(), TagCommand(), ReleaseCommand(), BranchCommand() ) try: command.run() except GitFlowError as e: command.error(str(e)) except Exception as e: command.error("Ocurrió un error inesperado: " + str(e)) return if __name__ == "__main__": main()