From 69126bc5102598974f5e03191f6ba83e1a3ed3ea Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Wed, 12 Mar 2025 12:34:23 +0100 Subject: [PATCH] feat: enhance service status check to return container count in logs --- bin/actions/service.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/bin/actions/service.py b/bin/actions/service.py index b2df543..aa070ae 100755 --- a/bin/actions/service.py +++ b/bin/actions/service.py @@ -73,10 +73,10 @@ def cmd_logs(args): return run_docker_compose(cmd, service_name=args.service) def check_service_running(service_name): - """Check if service has running containers""" + """Check if service has running containers and return the count""" compose_file = get_service_path(service_name) if not compose_file: - return False + return 0 result = subprocess.run( ["docker", "compose", "-f", compose_file, "ps", "--quiet"], @@ -84,7 +84,9 @@ def check_service_running(service_name): text=True ) - return bool(result.stdout.strip()) + # Count non-empty lines to get container count + containers = [line for line in result.stdout.strip().split('\n') if line] + return len(containers) def cmd_list(args): """List available Docker services""" @@ -102,9 +104,16 @@ def cmd_list(args): println("Available Docker services:", 'blue') for service in sorted(services): - is_running = check_service_running(service) - status = "[RUNNING]" if is_running else "[STOPPED]" - color = "green" if is_running else "red" + container_count = check_service_running(service) + is_running = container_count > 0 + + if is_running: + status = f"[RUNNING - {container_count} container{'s' if container_count > 1 else ''}]" + color = "green" + else: + status = "[STOPPED]" + color = "red" + printfe(color, f" - {service:<20} {status}") return 0