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

94 lines
2.6 KiB
TypeScript
Raw Normal View History

2026-04-05 21:09:33 -05:00
/**
* Flow management CLI commands.
*
* Python reference: trustgraph-cli/trustgraph/cli/start_flow.py, stop_flow.py, etc.
*/
import type { Command } from "commander";
import { createSocket, getOpts } from "./util.js";
export function registerFlowCommands(program: Command): void {
const flow = program
.command("flow")
.description("Flow management");
flow
.command("list")
.description("List active flows")
.action(async (_opts, cmd) => {
const opts = getOpts(cmd);
const socket = await createSocket(opts);
try {
2026-04-05 22:44:45 -05:00
const flows = socket.flows();
const ids = await flows.getFlows();
console.log(JSON.stringify(ids, null, 2));
2026-04-05 21:09:33 -05:00
} finally {
2026-04-05 22:44:45 -05:00
socket.close();
2026-04-05 21:09:33 -05:00
}
});
flow
2026-04-05 22:44:45 -05:00
.command("get")
.description("Get a flow definition")
.argument("<id>", "Flow ID")
.action(async (id: string, _opts, cmd) => {
2026-04-05 21:09:33 -05:00
const opts = getOpts(cmd);
const socket = await createSocket(opts);
try {
2026-04-05 22:44:45 -05:00
const flows = socket.flows();
const def = await flows.getFlow(id);
console.log(JSON.stringify(def, null, 2));
2026-04-05 21:09:33 -05:00
} finally {
2026-04-05 22:44:45 -05:00
socket.close();
2026-04-05 21:09:33 -05:00
}
});
flow
2026-04-05 22:44:45 -05:00
.command("start")
.description("Start a flow")
.argument("<id>", "Flow ID")
.requiredOption("-b, --blueprint <name>", "Blueprint name")
.option("-d, --description <text>", "Flow description", "")
.option("-p, --parameters <json>", "Parameters as JSON")
.action(async (id: string, cmdOpts, cmd) => {
2026-04-05 21:09:33 -05:00
const opts = getOpts(cmd);
const socket = await createSocket(opts);
try {
2026-04-05 22:44:45 -05:00
const flows = socket.flows();
2026-05-12 08:06:58 -05:00
const rawParameters = cmdOpts.parameters as string | undefined;
const params = rawParameters !== undefined && rawParameters.length > 0
? JSON.parse(rawParameters)
2026-04-05 22:44:45 -05:00
: undefined;
const resp = await flows.startFlow(
id,
cmdOpts.blueprint as string,
cmdOpts.description as string,
params as Record<string, unknown> | undefined,
);
2026-04-05 21:09:33 -05:00
console.log(JSON.stringify(resp, null, 2));
} finally {
2026-04-05 22:44:45 -05:00
socket.close();
2026-04-05 21:09:33 -05:00
}
});
flow
2026-04-05 22:44:45 -05:00
.command("stop")
.description("Stop a flow")
.argument("<id>", "Flow ID")
.action(async (id: string, _opts, cmd) => {
2026-04-05 21:09:33 -05:00
const opts = getOpts(cmd);
const socket = await createSocket(opts);
try {
2026-04-05 22:44:45 -05:00
const flows = socket.flows();
const resp = await flows.stopFlow(id);
2026-04-05 21:09:33 -05:00
console.log(JSON.stringify(resp, null, 2));
} finally {
2026-04-05 22:44:45 -05:00
socket.close();
2026-04-05 21:09:33 -05:00
}
});
}