import typer from agebd.utils import get_git_root, init_logging from config.paths import Paths from core.enums import GuiOption from core.git import GitRepoManager from core.service_creator import ServiceCreator from models import ServiceRegistry from models.context import ServicesContext from models.gui_config import GuiConfig service = typer.Typer(no_args_is_help=True) REPO_ROOT = get_git_root(__file__) @service.command( no_args_is_help=True, help="Running this command will create a new branch 'feature/add-service-', " "add all the required files for a new service, and push. " "See: https://gitea.psi.ch/sls/hla_framework_bd/branches", ) def add( name: str = typer.Option( ..., "--name", "-n", help="Camelcase name of the service. The name will be used as is in the gui, and converted to uppercase/lowercase where necessary", ), ioc_owner: str = typer.Option( ..., "--ioc-owner", "-o", help="Owner of the IOC that will be created. " "This is the person that will be contacted by picket service in case of an issue. E.g. 'armborst'", ), ioc_description: str = typer.Option( ..., "--ioc-description", "-d", help="See /docs/user/ioc/iocs_overview.md for examples", ), gui_option: GuiOption = typer.Option( GuiOption.NEW, "--gui", "-g", help="By default, a new GUI is created. You can specificy if a GUI already exists, " "and this service should use that GUI, or if no GUI is needed for this service", ), raw_ui_filename: str | None = typer.Option( None, "--gui-existing-service-name", "-s", help="If '--gui=existing', specify the name of an existing service (in CamelCase) whose GUI this new service should use", ), ): init_logging() if gui_option == GuiOption.NEW: raw_ui_filename = name gui_config = GuiConfig(option=gui_option, raw_ui_filename=raw_ui_filename) ctx = ServicesContext.load_from_disk(Paths()) service_creator = ServiceCreator(ctx=ctx, repo_manager=GitRepoManager(REPO_ROOT)) service_creator.add_service( name=name, ioc_owner=ioc_owner, ioc_description=ioc_description, gui_config=gui_config, ) @service.command() def list(): paths = Paths() registry = ServiceRegistry.read_from_file(paths.service_registry_file) services = registry.get_services() for service in services: print(service)