feat(cli): add prefix matching to 'box swarm status'
This commit is contained in:
+16
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user