From 3a03e0753c59b574e2a027f23ad5dcf430e674b2 Mon Sep 17 00:00:00 2001 From: yeuimu <2197651308@qq.com> Date: Sun, 16 Aug 2026 17:47:17 +0000 Subject: [PATCH] fix(cli): read commander's camelCase keys for kebab-case flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commander stores --code-file as opts.codeFile (kebab keys are never set), so 'action update --code-file' silently no-opped (workflow.ts read opts['code-file']) and 'auth token create --base-ids/--full-access' never applied (auth.ts read the kebab keys). The 'action add' path was unaffected because buildActionConfig's pick() checks both forms. - workflow.ts action update: opts['code-file'] ?? opts.codeFile - auth.ts token create: baseIds/fullAccess dual-form read - verified live: action update --code-file now persists the new script (was silently keeping old code); commander dual-key behavior confirmed by direct parse (kebab keys absent, camelCase present, and this commander version drops the --base-ids VALUE entirely — the dual read covers both) --- dist/commands/auth.js | 10 +++++++--- dist/commands/workflow.js | 7 +++++-- src/commands/auth.ts | 20 ++++++++++++++++---- src/commands/workflow.ts | 7 +++++-- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/dist/commands/auth.js b/dist/commands/auth.js index f372aa6..2fe1881 100644 --- a/dist/commands/auth.js +++ b/dist/commands/auth.js @@ -95,16 +95,20 @@ function authCommand() { .option('--full-access', 'Grant full access') .option('--expires ', 'Expiry date YYYY-MM-DD (default 2099-12-31)', '2099-12-31') .action((0, ctx_1.run)(async (ctx, _args, o) => { + // commander stores --kebab-case flags camelCased (--base-ids -> + // opts.baseIds, --full-access -> opts.fullAccess); accept both. const opts = o; const scopes = opts.scopes.split(',').map((s) => s.trim()).filter(Boolean); - const baseIds = opts['base-ids'] - ? opts['base-ids'].split(',').map((s) => s.trim()) + const rawBaseIds = opts['base-ids'] ?? opts.baseIds; + const baseIds = rawBaseIds + ? rawBaseIds.split(',').map((s) => s.trim()) : undefined; + const fullAccess = Boolean(opts['full-access'] ?? opts.fullAccess); const created = (await ctx.client.createAccessToken({ name: opts.name, scopes, baseIds, - hasFullAccess: !!opts['full-access'], + hasFullAccess: fullAccess, expiredTime: opts.expires, })); if (ctx.json) diff --git a/dist/commands/workflow.js b/dist/commands/workflow.js index 2ec46a9..6fe9a7e 100644 --- a/dist/commands/workflow.js +++ b/dist/commands/workflow.js @@ -463,8 +463,11 @@ function actionCommand() { else { // Granular update: merge only the flags the user actually passed. config = { ...config }; - if (opts.code !== undefined || opts['code-file'] !== undefined) { - config.code = opts['code-file'] ? readFile(opts['code-file']) : opts.code; + // commander stores --kebab-case flags camelCased (--code-file -> + // opts.codeFile); accept both forms like buildActionConfig's pick(). + const codeFile = opts['code-file'] ?? opts.codeFile; + if (opts.code !== undefined || codeFile !== undefined) { + config.code = codeFile ? readFile(codeFile) : opts.code; } if (opts.timeout !== undefined) config.timeout = Number(opts.timeout); diff --git a/src/commands/auth.ts b/src/commands/auth.ts index cb74cc2..8819739 100644 --- a/src/commands/auth.ts +++ b/src/commands/auth.ts @@ -107,16 +107,28 @@ export function authCommand(): Command { .option('--expires ', 'Expiry date YYYY-MM-DD (default 2099-12-31)', '2099-12-31') .action( run(async (ctx, _args, o) => { - const opts = o as { name: string; scopes: string; 'base-ids'?: string; 'full-access'?: boolean; expires: string }; + // commander stores --kebab-case flags camelCased (--base-ids -> + // opts.baseIds, --full-access -> opts.fullAccess); accept both. + const opts = o as { + name: string; + scopes: string; + 'base-ids'?: string; + baseIds?: string; + 'full-access'?: boolean; + fullAccess?: boolean; + expires: string; + }; const scopes = opts.scopes.split(',').map((s) => s.trim()).filter(Boolean); - const baseIds = opts['base-ids'] - ? opts['base-ids'].split(',').map((s) => s.trim()) + const rawBaseIds = opts['base-ids'] ?? opts.baseIds; + const baseIds = rawBaseIds + ? rawBaseIds.split(',').map((s) => s.trim()) : undefined; + const fullAccess = Boolean(opts['full-access'] ?? opts.fullAccess); const created = (await ctx.client.createAccessToken({ name: opts.name, scopes, baseIds, - hasFullAccess: !!opts['full-access'], + hasFullAccess: fullAccess, expiredTime: opts.expires, })) as { id: string; token: string }; if (ctx.json) printJson(created); diff --git a/src/commands/workflow.ts b/src/commands/workflow.ts index f62e20e..28d83d6 100644 --- a/src/commands/workflow.ts +++ b/src/commands/workflow.ts @@ -523,8 +523,11 @@ export function actionCommand(): Command { else { // Granular update: merge only the flags the user actually passed. config = { ...config }; - if (opts.code !== undefined || opts['code-file'] !== undefined) { - config.code = opts['code-file'] ? readFile(opts['code-file']) : opts.code; + // commander stores --kebab-case flags camelCased (--code-file -> + // opts.codeFile); accept both forms like buildActionConfig's pick(). + const codeFile = opts['code-file'] ?? opts.codeFile; + if (opts.code !== undefined || codeFile !== undefined) { + config.code = codeFile ? readFile(codeFile) : opts.code; } if (opts.timeout !== undefined) config.timeout = Number(opts.timeout); if (opts.dependencies !== undefined) {