;; canon: bot.git src/bot/fleet/link.cljs (ported from src/fleet/link.ts)
;;
;; Provisioning helper: print a bot identity's friend link (creating the seed
;; if it doesn't exist yet). Used by install-fleet.sh to fill the configs'
;; sibling arrays before any bot ever runs.
;;
;; node dist/fleet/link.js <seedFile> <name>
(ns __NAME__.fleet.link
(:require ["node:path" :as path]
["ardegazu-peer-kit" :refer (loadIdentity suiteFriendLink)]))
(defn- run []
(let [seed-file (aget js/process.argv 2)
name (aget js/process.argv 3)]
(if (or (not (some? seed-file)) (not (some? name)))
(do (js/console.error "usage: node dist/fleet/link.js <seedFile> <name>")
(js/process.exit 1))
(-> (loadIdentity #js {:seedFile seed-file :name name})
(.then (fn [suite] (suiteFriendLink suite)))
(.then (fn [link] (js/console.log link)))))))
(defn init
"Run only as the process entry script (`node dist/fleet/link.js …`) — an
import of this module (tests, tooling) must stay side-effect free."
[]
(when (identical? (some-> (aget js/process.argv 1) (path/basename)) "link.js")
(run)))