feat(cli): add consistent get/list/new subcommands for all item types (#8047)
* feat(cli): add consistent get/list/new subcommands for all item types Make the CLI consistent so every item type (script, flow, app, resource, resource-type, variable, schedule, folder, trigger) supports get/list/new subcommands, enabling the CLI to be used as a full API client in bash scripts with jq piping. - Add --json flag to all list commands for machine-readable output - Register explicit "list" subcommand alongside default action - Add "get <path> [--json]" subcommand to fetch single items from API - Rename "bootstrap" to "new" for script/flow, keep "bootstrap" as alias - Add "new" subcommand for resource, resource-type, variable, schedule, folder, and trigger to create local template YAML files - Update cli-commands skill documentation for wmill init - Add integration tests for all new commands Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * all * feat: install wmill CLI in Docker images and use it for bash variable/resource access - Install windmill-cli via bun in all Dockerfiles that include bun - DockerfileCli: switch from node:slim to oven/bun:slim - CLI: auto-configure from WM_WORKSPACE/WM_TOKEN/BASE_INTERNAL_URL env vars as last-resort fallback when no workspace is configured - Frontend: replace curl-based bash snippets with wmill variable/resource get - Add backend integration tests for wmill CLI in bash scripts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ci): install windmill-cli in backend test workflow Ensures wmill is available on PATH for bash integration tests that use `wmill variable get` and `wmill resource get`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor(cli): replace @std/* Deno dependencies with Node.js equivalents Replace @std/log with a lightweight custom logger (core/log.ts), @std/path with node:path, and @std/yaml with the yaml npm package. Also fix process hang on exit, add --node option to install_dev.sh, and add missing hasRequiredPermissions to NpmProvider. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * all * all * all * refactor(cli): replace @ayonli/jsext and @std/encoding with lightweight alternatives Replace @ayonli/jsext (8.4MB) with tar-stream (32kB) for tar creation, replace @std/encoding with Node.js Buffer.toString("hex"), and fix @windmill-labs/shared-utils to use direct npm instead of JSR mirror. Also resolve merge conflicts in sync.ts and fix pre-existing type errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(cli): use singleQuote YAML output and pass yamlOptions in gitsync pull The yaml library defaults to double quotes, but the codebase (and tests) expect single-quoted strings. Add singleQuote: true to yamlOptions and pass yamlOptions to gitsync-settings pull writeFile calls. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * all * all * fix(cli): address code review feedback - Install CLI from source in backend tests instead of npm - Fix script bootstrap catch block to re-throw "File already exists" - Add type-safe local variable after trigger kind validation - Use created_by instead of policy.on_behalf_of for app get output - Note --kind is recommended for faster trigger lookup in help text - Document node symlink purpose in Dockerfiles Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ci): use /usr/bin for wmill wrapper to ensure it's in PATH Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(ci): install wmill to ~/.local/bin to avoid permission issues Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ci(backend): switch to Blacksmith runner and add cargo caching - Switch from ubicloud-standard-16 to blacksmith-16vcpu-ubuntu-2404 for faster NVMe-backed builds - Add stickydisk for cargo target directory (persistent NVMe cache across runs) - Add cache for cargo registry and git dependencies - Upgrade DuckDB FFI cache from actions/cache@v3 to useblacksmith/cache@v1 - Enable CARGO_INCREMENTAL=1 to benefit from persistent target cache Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix ci --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { stat } from "node:fs/promises";
|
||||
import { stat, writeFile } from "node:fs/promises";
|
||||
import { stringify as yamlStringify } from "yaml";
|
||||
|
||||
import * as wmill from "../../../gen/services.gen.ts";
|
||||
import {
|
||||
@@ -18,8 +19,8 @@ import {
|
||||
import { Command } from "@cliffy/command";
|
||||
import { Table } from "@cliffy/table";
|
||||
import { colors } from "@cliffy/ansi/colors";
|
||||
import * as log from "@std/log";
|
||||
import { SEPARATOR as SEP } from "@std/path";
|
||||
import * as log from "../../core/log.ts";
|
||||
import { sep as SEP } from "node:path";
|
||||
import {
|
||||
GlobalOptions,
|
||||
isSuperset,
|
||||
@@ -295,37 +296,192 @@ export async function pushNativeTrigger(
|
||||
}
|
||||
}
|
||||
|
||||
async function list(opts: GlobalOptions) {
|
||||
const triggerTemplates: Record<TriggerType, Record<string, any>> = {
|
||||
http: {
|
||||
script_path: "",
|
||||
is_flow: false,
|
||||
route_path: "",
|
||||
http_method: "get",
|
||||
is_async: false,
|
||||
requires_auth: true,
|
||||
},
|
||||
websocket: {
|
||||
script_path: "",
|
||||
is_flow: false,
|
||||
url: "",
|
||||
enabled: false,
|
||||
},
|
||||
kafka: {
|
||||
script_path: "",
|
||||
is_flow: false,
|
||||
kafka_resource_path: "",
|
||||
group_id: "",
|
||||
topics: [],
|
||||
enabled: false,
|
||||
},
|
||||
nats: {
|
||||
script_path: "",
|
||||
is_flow: false,
|
||||
nats_resource_path: "",
|
||||
subjects: [],
|
||||
enabled: false,
|
||||
},
|
||||
postgres: {
|
||||
script_path: "",
|
||||
is_flow: false,
|
||||
postgres_resource_path: "",
|
||||
publication_name: "",
|
||||
replication_slot_name: "",
|
||||
enabled: false,
|
||||
},
|
||||
mqtt: {
|
||||
script_path: "",
|
||||
is_flow: false,
|
||||
mqtt_resource_path: "",
|
||||
topics: [],
|
||||
subscribe_qos: 0,
|
||||
enabled: false,
|
||||
},
|
||||
sqs: {
|
||||
script_path: "",
|
||||
is_flow: false,
|
||||
sqs_resource_path: "",
|
||||
queue_url: "",
|
||||
enabled: false,
|
||||
},
|
||||
gcp: {
|
||||
script_path: "",
|
||||
is_flow: false,
|
||||
gcp_resource_path: "",
|
||||
subscription_id: "",
|
||||
topic_id: "",
|
||||
enabled: false,
|
||||
},
|
||||
email: {
|
||||
script_path: "",
|
||||
is_flow: false,
|
||||
enabled: false,
|
||||
},
|
||||
};
|
||||
|
||||
async function newTrigger(opts: GlobalOptions & { kind: string }, path: string) {
|
||||
if (!validatePath(path)) {
|
||||
return;
|
||||
}
|
||||
if (!opts.kind) {
|
||||
throw new Error("--kind is required. Valid kinds: " + TRIGGER_TYPES.join(", "));
|
||||
}
|
||||
if (!checkIfValidTrigger(opts.kind)) {
|
||||
throw new Error("Invalid trigger kind: " + opts.kind + ". Valid kinds: " + TRIGGER_TYPES.join(", "));
|
||||
}
|
||||
const kind: TriggerType = opts.kind;
|
||||
const filePath = `${path}.${kind}_trigger.yaml`;
|
||||
try {
|
||||
await stat(filePath);
|
||||
throw new Error("File already exists: " + filePath);
|
||||
} catch (e: any) {
|
||||
if (e.message?.startsWith("File already exists")) throw e;
|
||||
}
|
||||
const template = triggerTemplates[kind];
|
||||
await writeFile(filePath, yamlStringify(template), {
|
||||
flag: "wx",
|
||||
encoding: "utf-8",
|
||||
});
|
||||
log.info(colors.green(`Created ${filePath}`));
|
||||
}
|
||||
|
||||
async function get(opts: GlobalOptions & { json?: boolean; kind?: string }, path: string) {
|
||||
const workspace = await resolveWorkspace(opts);
|
||||
await requireLogin(opts);
|
||||
|
||||
const httpTriggers = await wmill.listHttpTriggers({
|
||||
workspace: workspace.workspaceId,
|
||||
});
|
||||
const websocketTriggers = await wmill.listWebsocketTriggers({
|
||||
workspace: workspace.workspaceId,
|
||||
});
|
||||
const kafkaTriggers = await wmill.listKafkaTriggers({
|
||||
workspace: workspace.workspaceId,
|
||||
});
|
||||
const natsTriggers = await wmill.listNatsTriggers({
|
||||
workspace: workspace.workspaceId,
|
||||
});
|
||||
const postgresTriggers = await wmill.listPostgresTriggers({
|
||||
workspace: workspace.workspaceId,
|
||||
});
|
||||
const mqttTriggers = await wmill.listMqttTriggers({
|
||||
workspace: workspace.workspaceId,
|
||||
});
|
||||
const sqsTriggers = await wmill.listSqsTriggers({
|
||||
workspace: workspace.workspaceId,
|
||||
});
|
||||
const gcpTriggers = await wmill.listGcpTriggers({
|
||||
workspace: workspace.workspaceId,
|
||||
});
|
||||
const emailTriggers = await wmill.listEmailTriggers({
|
||||
workspace: workspace.workspaceId,
|
||||
});
|
||||
if (opts.kind) {
|
||||
if (!checkIfValidTrigger(opts.kind)) {
|
||||
throw new Error("Invalid trigger kind: " + opts.kind + ". Valid kinds: " + TRIGGER_TYPES.join(", "));
|
||||
}
|
||||
const trigger = await getTrigger(opts.kind, workspace.workspaceId, path);
|
||||
if (opts.json) {
|
||||
console.log(JSON.stringify(trigger));
|
||||
} else {
|
||||
console.log(colors.bold("Path:") + " " + (trigger as any).path);
|
||||
console.log(colors.bold("Kind:") + " " + opts.kind);
|
||||
console.log(colors.bold("Enabled:") + " " + ((trigger as any).enabled ?? "-"));
|
||||
console.log(colors.bold("Script Path:") + " " + ((trigger as any).script_path ?? ""));
|
||||
console.log(colors.bold("Is Flow:") + " " + ((trigger as any).is_flow ? "true" : "false"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Try all trigger types and collect matches
|
||||
const matches: { kind: string; trigger: any }[] = [];
|
||||
for (const kind of TRIGGER_TYPES) {
|
||||
try {
|
||||
const trigger = await getTrigger(kind, workspace.workspaceId, path);
|
||||
matches.push({ kind, trigger });
|
||||
} catch {
|
||||
// not found for this kind
|
||||
}
|
||||
}
|
||||
|
||||
if (matches.length === 0) {
|
||||
throw new Error("No trigger found at path: " + path);
|
||||
}
|
||||
|
||||
if (matches.length === 1) {
|
||||
const { kind, trigger } = matches[0];
|
||||
if (opts.json) {
|
||||
console.log(JSON.stringify(trigger));
|
||||
} else {
|
||||
console.log(colors.bold("Path:") + " " + trigger.path);
|
||||
console.log(colors.bold("Kind:") + " " + kind);
|
||||
console.log(colors.bold("Enabled:") + " " + (trigger.enabled ?? "-"));
|
||||
console.log(colors.bold("Script Path:") + " " + (trigger.script_path ?? ""));
|
||||
console.log(colors.bold("Is Flow:") + " " + (trigger.is_flow ? "true" : "false"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Multiple matches — ask user to specify --kind
|
||||
console.log("Multiple triggers found at path " + path + ":");
|
||||
for (const m of matches) {
|
||||
console.log(" - " + m.kind);
|
||||
}
|
||||
console.log("Please specify --kind <type> to select one.");
|
||||
}
|
||||
|
||||
async function listOrEmpty<T>(fn: () => Promise<T[]>): Promise<T[]> {
|
||||
try {
|
||||
return await fn();
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function list(opts: GlobalOptions & { json?: boolean }) {
|
||||
const workspace = await resolveWorkspace(opts);
|
||||
await requireLogin(opts);
|
||||
|
||||
const ws = workspace.workspaceId;
|
||||
const [
|
||||
httpTriggers,
|
||||
websocketTriggers,
|
||||
kafkaTriggers,
|
||||
natsTriggers,
|
||||
postgresTriggers,
|
||||
mqttTriggers,
|
||||
sqsTriggers,
|
||||
gcpTriggers,
|
||||
emailTriggers,
|
||||
] = await Promise.all([
|
||||
listOrEmpty(() => wmill.listHttpTriggers({ workspace: ws })),
|
||||
listOrEmpty(() => wmill.listWebsocketTriggers({ workspace: ws })),
|
||||
listOrEmpty(() => wmill.listKafkaTriggers({ workspace: ws })),
|
||||
listOrEmpty(() => wmill.listNatsTriggers({ workspace: ws })),
|
||||
listOrEmpty(() => wmill.listPostgresTriggers({ workspace: ws })),
|
||||
listOrEmpty(() => wmill.listMqttTriggers({ workspace: ws })),
|
||||
listOrEmpty(() => wmill.listSqsTriggers({ workspace: ws })),
|
||||
listOrEmpty(() => wmill.listGcpTriggers({ workspace: ws })),
|
||||
listOrEmpty(() => wmill.listEmailTriggers({ workspace: ws })),
|
||||
]);
|
||||
const triggers = [
|
||||
...httpTriggers.map((x) => ({ path: x.path, kind: "http" })),
|
||||
...websocketTriggers.map((x) => ({ path: x.path, kind: "websocket" })),
|
||||
@@ -338,12 +494,16 @@ async function list(opts: GlobalOptions) {
|
||||
...emailTriggers.map((x) => ({ path: x.path, kind: "email" })),
|
||||
];
|
||||
|
||||
new Table()
|
||||
.header(["Path", "Kind"])
|
||||
.padding(2)
|
||||
.border(true)
|
||||
.body(triggers.map((x) => [x.path, x.kind]))
|
||||
.render();
|
||||
if (opts.json) {
|
||||
console.log(JSON.stringify(triggers));
|
||||
} else {
|
||||
new Table()
|
||||
.header(["Path", "Kind"])
|
||||
.padding(2)
|
||||
.border(true)
|
||||
.body(triggers.map((x) => [x.path, x.kind]))
|
||||
.render();
|
||||
}
|
||||
}
|
||||
|
||||
function checkIfValidTrigger(kind: string | undefined): kind is TriggerType {
|
||||
@@ -401,7 +561,20 @@ async function push(opts: GlobalOptions, filePath: string, remotePath: string) {
|
||||
|
||||
const command = new Command()
|
||||
.description("trigger related commands")
|
||||
.option("--json", "Output as JSON (for piping to jq)")
|
||||
.action(list as any)
|
||||
.command("list", "list all triggers")
|
||||
.option("--json", "Output as JSON (for piping to jq)")
|
||||
.action(list as any)
|
||||
.command("get", "get a trigger's details")
|
||||
.arguments("<path:string>")
|
||||
.option("--json", "Output as JSON (for piping to jq)")
|
||||
.option("--kind <kind:string>", "Trigger kind (http, websocket, kafka, nats, postgres, mqtt, sqs, gcp, email). Recommended for faster lookup")
|
||||
.action(get as any)
|
||||
.command("new", "create a new trigger locally")
|
||||
.arguments("<path:string>")
|
||||
.option("--kind <kind:string>", "Trigger kind (required: http, websocket, kafka, nats, postgres, mqtt, sqs, gcp, email)")
|
||||
.action(newTrigger as any)
|
||||
.command(
|
||||
"push",
|
||||
"push a local trigger spec. This overrides any remote versions."
|
||||
|
||||
Reference in New Issue
Block a user