diff --git a/cli/src/core/models.py b/cli/src/core/models.py index d81cf17..5df7bad 100644 --- a/cli/src/core/models.py +++ b/cli/src/core/models.py @@ -73,6 +73,14 @@ class ServiceRegistry(BaseModel): registry = ServiceRegistry.model_validate(d) return registry + def get_service(self, name: str) -> Service: + for svc_data in self.services: + service = Service(**svc_data) + if name == service.name_lower: + return service + + raise ValueError(f"Could not find service with name: {name}") + def get_services(self) -> list[Service]: return [Service(**svc_data) for svc_data in self.services] diff --git a/cli/src/ioc.py b/cli/src/ioc.py index 054ea2a..0ad52e1 100644 --- a/cli/src/ioc.py +++ b/cli/src/ioc.py @@ -14,11 +14,13 @@ IOC_PLAYBOOK_INSTALL = ANSIBLE_PLAYBOOKS_DIR / "ioc-install.yml" IOC_PLAYBOOK_RESTART = ANSIBLE_PLAYBOOKS_DIR / "ioc-restart.yml" IOC_PLAYBOOK_START = ANSIBLE_PLAYBOOKS_DIR / "ioc-start.yml" +SERVICE_NAME_HELP = "Service name in lower case" + @ioc.command(no_args_is_help=True) def install( env: IOC_ENV = typer.Option(..., "--env"), - service_name_lower: str = typer.Option(..., "--service-name", "-s"), + service_name_lower: str = typer.Option(..., "--service-name", "-s", help=SERVICE_NAME_HELP), branch_name: str | None = typer.Option(None, "--branch-name", "-b"), ): if branch_name is None: @@ -48,9 +50,11 @@ def install_all( @ioc.command(no_args_is_help=True) def start( env: IOC_ENV = typer.Option(..., "--env"), - ioc_port: int = typer.Option(..., "--port", "-p"), + service_name_lower: str = typer.Option(..., "--service-name", "-s", help=SERVICE_NAME_HELP), ): - ioc_port_var = f"ioc_port={ioc_port}" + registry = ServiceRegistry.read_from_config() + service = registry.get_service(name=service_name_lower) + ioc_port_var = f"ioc_port={service.ioc_port}" run_playbook(playbook=str(IOC_PLAYBOOK_START), env=env, vars=[ioc_port_var]) @@ -71,7 +75,7 @@ def start_all( @ioc.command(no_args_is_help=True) def restart( env: IOC_ENV = typer.Option(..., "--env"), - service_name_lower: str = typer.Option(..., "--service-name", "-s"), + service_name_lower: str = typer.Option(..., "--service-name", "-s", help=SERVICE_NAME_HELP), branch_name: str | None = typer.Option(None, "--branch-name", "-b"), ): if branch_name is None: