feat: enhance service status reporting with JSON output and add related tests
This commit is contained in:
@@ -363,6 +363,16 @@ def status_service(profile: str, ref: ServiceRef) -> None:
|
||||
print(f"{ref.name}: {status['status']} pid={status['pid'] or '-'} ({status['health']['detail']})")
|
||||
|
||||
|
||||
def status_report(profile: str, refs: list[ServiceRef]) -> dict[str, Any]:
|
||||
"""Return lightweight machine-readable live service state."""
|
||||
return {
|
||||
"profile": profile,
|
||||
"workspace": str(ROOT),
|
||||
"runtime": str(RUNTIME_DIR),
|
||||
"services": [service_status(profile, ref) for ref in refs],
|
||||
}
|
||||
|
||||
|
||||
def tail_log(profile: str, service: str, lines: int) -> None:
|
||||
path = log_path(profile, service)
|
||||
if not path.is_file():
|
||||
@@ -480,8 +490,11 @@ def main() -> None:
|
||||
for ref in refs:
|
||||
start_service(args.profile, ref, manifest, started)
|
||||
elif args.action == "status":
|
||||
for ref in refs:
|
||||
status_service(args.profile, ref)
|
||||
if args.json:
|
||||
print(json.dumps(status_report(args.profile, refs), ensure_ascii=False, indent=2, sort_keys=True))
|
||||
else:
|
||||
for ref in refs:
|
||||
status_service(args.profile, ref)
|
||||
elif args.action == "logs":
|
||||
if not args.services:
|
||||
raise SystemExit("logs requires at least one service name")
|
||||
|
||||
Reference in New Issue
Block a user