feat: enhance service status check to return container count in logs
Some checks failed
Nix Format Check / check-format (push) Failing after 36s

This commit is contained in:
2025-03-12 12:34:23 +01:00
parent f31e77a2f3
commit 69126bc510

View File

@ -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