import type { Command } from "commander"; import { getClient, parseKvPairs } from "../context.ts"; import { rootOpts, run } from "./run.ts"; export function registerCustomFieldCommands(program: Command): void { const fields = program .command("custom-fields") .description("Custom field operations"); fields.command("get ").action((id, _opts, cmd) => run(cmd, async () => { const { client } = getClient(rootOpts(cmd).profile); return client.customFieldGet(id); }), ); fields .command("create") .requiredOption("--board ", "Board id") .requiredOption("--name ", "Field name") .requiredOption("--type ", "text|number|date|checkbox|list") .action((opts, cmd) => run(cmd, async () => { const { client } = getClient(rootOpts(cmd).profile); return client.customFieldCreate({ idModel: opts.board, modelType: "board", name: opts.name, type: opts.type, }); }), ); fields .command("update ") .option("--params ", "key=value params") .action((id, opts, cmd) => run(cmd, async () => { const { client } = getClient(rootOpts(cmd).profile); return client.customFieldUpdate(id, parseKvPairs(opts.params)); }), ); fields.command("delete ").action((id, _opts, cmd) => run(cmd, async () => { const { client } = getClient(rootOpts(cmd).profile); return client.customFieldDelete(id); }), ); fields .command("set-item ") .requiredOption("--card ", "Card id") .option("--text ", "Text value") .option("--number ", "Number value") .option("--date ", "Date value") .option("--checked ", "Checkbox value") .action((fieldId, opts, cmd) => run(cmd, async () => { const { client } = getClient(rootOpts(cmd).profile); return client.customFieldUpdateItem(opts.card, fieldId, { value: { text: opts.text, number: opts.number, date: opts.date, checked: opts.checked, }, }); }), ); }