diff --git a/deployer/index.ts b/deployer/index.ts index ab0b00c..96d48d5 100644 --- a/deployer/index.ts +++ b/deployer/index.ts @@ -1,14 +1,18 @@ import { ssh, SSH } from './ssh.js' import { Expression } from './nix.js' +type Dictionary = Record type Command = () => Promise +type Setter = (props: Dictionary) => void class Cmd { - registry: Record = {}; + registry: Dictionary = {}; + settings: Dictionary = {}; register(obj: string, action: string, fn: Command) { this.registry[`${obj}.${action}`] = fn } - registerAll(obj: string, intf: Object & { _commands?: string[] }) { + registerAll(obj: string, intf: Object & { _commands?: string[], set?: Setter }) { if (!intf._commands) return + if (intf.set) this.settings[obj] = intf.set.bind(intf) const proto = Object.getPrototypeOf(intf) for (const name of intf._commands) { if (name != "constructor" && typeof proto[name] === "function") { @@ -18,6 +22,14 @@ class Cmd { } async run() { const opt = argv._[0] + for (const k of Object.keys(argv)) { + if (k === "_") continue + if (this.settings[k]) { + this.settings[k](argv[k]) + } else { + throw new Error("unknown object " + k) + } + } if (opt == "__autocompletes") { for (const k of Object.keys(this.registry)) { console.log(k) @@ -62,7 +74,7 @@ class Machine { return this.hostname } else { // todo: directify - return `${this.name}.vpn.yori.cc` + return `${this.name}.home.yori.cc` } } async findIP(): Promise { @@ -106,6 +118,10 @@ class MachineInterface { // hack: delete this._commands } + set(props: Dictionary) { + console.log("setting", props) + Object.assign(this.machine, props) + } @cmd async ssh() { (await this.machine.ssh()).interactive()