feat(cli): add prefix matching to 'box swarm status'

This commit is contained in:
operator
2026-10-05 16:23:07 +00:00
parent 0ca0fd0c1a
commit c13ee20ea4
+16 -1
View File
@@ -3145,7 +3145,22 @@ def cmd_swarm_list(args):
def cmd_swarm_status(args):
cmd = ["python3", str(BIN_DIR / "box-ctl.py"), "swarm-status", args.swarm_id]
sid = args.swarm_id
if not sid.startswith("sw-"):
sid = "sw-" + sid
# Support prefix matching if exact ID is truncated (e.g. 18 chars)
sw_file = Path(__file__).parent.parent / "swarms.json"
if sw_file.exists():
try:
import json
data = json.loads(sw_file.read_text(encoding="utf-8"))
if sid not in data:
matches = [k for k in data.keys() if k.startswith(sid)]
if len(matches) == 1:
sid = matches[0]
except Exception:
pass
cmd = ["python3", str(BIN_DIR / "box-ctl.py"), "swarm-status", sid]
res = subprocess.run(cmd, capture_output=True, text=True)
if args.json:
sys.stdout.write(res.stdout)