trustgraph/ts/packages/cli/src/commands/util.ts

29 lines
622 B
TypeScript
Raw Normal View History

2026-04-05 21:09:33 -05:00
/**
* Shared CLI utilities.
*/
import type { Command } from "commander";
import { SocketManager } from "@trustgraph/mcp";
export interface CliOpts {
gateway: string;
token?: string;
flow: string;
}
export function getOpts(cmd: Command): CliOpts {
// Walk up to root command to get global options
let root = cmd;
while (root.parent) root = root.parent;
return root.opts() as CliOpts;
}
export async function createSocket(opts: CliOpts): Promise<SocketManager> {
const socket = new SocketManager({
gatewayUrl: opts.gateway,
token: opts.token,
});
await socket.connect();
return socket;
}