feat: add remote API help listing
This commit is contained in:
parent
c25a8a84e0
commit
05245a8bba
|
|
@ -2,6 +2,30 @@
|
|||
set -euo pipefail
|
||||
REMOTE_URL="${JEANNIE_REMOTE_URL:-http://127.0.0.1:8787}"
|
||||
REMOTE_TOKEN="${JEANNIE_REMOTE_TOKEN:-${JEANNIE_SERVER_TOKEN:-}}"
|
||||
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
|
||||
export JEANNIE_REMOTE_URL="${REMOTE_URL}" REMOTE_TOKEN
|
||||
python3 - <<'PY'
|
||||
import json, os, sys, urllib.error, urllib.request
|
||||
url = os.environ["JEANNIE_REMOTE_URL"].rstrip("/")
|
||||
headers = {}
|
||||
if os.environ.get("REMOTE_TOKEN"):
|
||||
headers["Authorization"] = "Bearer " + os.environ["REMOTE_TOKEN"]
|
||||
request = urllib.request.Request(url + "/v1/commands", headers=headers, method="GET")
|
||||
try:
|
||||
with urllib.request.build_opener(urllib.request.ProxyHandler({})).open(request, timeout=15) as response:
|
||||
payload = json.loads(response.read())
|
||||
except urllib.error.HTTPError as exc:
|
||||
print(exc.read().decode(errors="replace"), file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
except urllib.error.URLError as exc:
|
||||
print(f"jeannie remote: cannot reach {url}: {exc.reason}", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
print(f"Jeannie remote API commands ({url}):")
|
||||
for command in payload.get("commands", []):
|
||||
print(f" {command}")
|
||||
PY
|
||||
exit 0
|
||||
fi
|
||||
if [[ $# -lt 1 ]]; then
|
||||
echo "Usage: ./jeannie remote <jeannie-command> [args...]" >&2
|
||||
exit 2
|
||||
|
|
|
|||
Loading…
Reference in New Issue