from __future__ import annotations from ..context import KnoeContext from knoe.core.ops import garage_store as garage_store_ops def _namespace(ctx: KnoeContext) -> str: return ctx.service_namespace or ctx.namespace def _run(ctx: KnoeContext, action: str) -> int: try: fn = getattr(garage_store_ops, action) fn( namespace=_namespace(ctx), env=ctx.env, project_root=ctx.project_root, mode=ctx.mode, log=ctx.logger, ) return 0 except Exception as e: ctx.err_logger(f"[garage] {action} failed: {e}") return 1 def initialize(ctx: KnoeContext): return _run(ctx, "initialize") def start(ctx: KnoeContext): return _run(ctx, "start") def update(ctx: KnoeContext): return _run(ctx, "update") def restart(ctx: KnoeContext): return _run(ctx, "restart") def stop(ctx: KnoeContext): return _run(ctx, "stop") def status(ctx: KnoeContext): try: ok = garage_store_ops.status(namespace=_namespace(ctx), env=ctx.env) return 0 if ok else 1 except Exception as e: ctx.err_logger(f"[garage] status failed: {e}") return 1