#!/usr/bin/env python3
# fake jq: implements only the two programs phase-03-core-verify.sh uses.
import sys, json
argv = sys.argv[1:]; prog = None; i = 0
while i < len(argv):
    a = argv[i]
    if a in ("-r", "--raw-output"): i += 1; continue
    if a == "--arg": i += 3; continue
    if prog is None and not a.startswith("-"): prog = a; i += 1; continue
    i += 1
try: data = json.load(sys.stdin)
except Exception: sys.exit(0)
if prog and ".models[]?.name" in prog:
    for m in (data.get("models") or []):
        if m.get("name") is not None: print(m["name"])
    sys.exit(0)
if prog and "keys[]?" in prog and "units" in prog:
    for app in (data.get("applications") or {}).values():
        for k in (app.get("units") or {}).keys(): print(k)
    sys.exit(0)
sys.exit(0)
