From 77632096bd9995472de69b97ee2ec2c6d8b68ca2 Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Sat, 10 Oct 2026 12:08:55 -0400 Subject: [PATCH 1/2] fix(cli): honor declared array option values Signed-off-by: Rudy Celekli --- tests/parser-array-options.test.mjs | 15 +++++++++++++++ v3/@claude-flow/cli/src/parser.ts | 21 +++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/parser-array-options.test.mjs diff --git a/tests/parser-array-options.test.mjs b/tests/parser-array-options.test.mjs new file mode 100644 index 0000000000..07d94ea82a --- /dev/null +++ b/tests/parser-array-options.test.mjs @@ -0,0 +1,15 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { CommandParser } from '../v3/@claude-flow/cli/src/parser.ts'; +const command = { name: 'build', description: '', options: [{ name: 'models', short: 'm', description: '', type: 'array' }] }; +test('declared array options produce arrays across long, short and repeated forms', () => { + const p = new CommandParser(); p.registerCommand(command); + for (const args of [['build', '--models', 'model-a'], ['build', '-m', 'model-a'], ['build', '--models=model-a']]) assert.equal(p.parse(args).flags.models.join(', '), 'model-a'); + assert.deepEqual(p.parse(['build', '--models=007', '-m', 'false']).flags.models, ['007', 'false']); +}); +test('custom array flags preserve text and accumulate values', () => { + const p = new CommandParser({ arrayFlags: ['model-ids'] }); assert.deepEqual(p.parse(['--model-ids=007', '--model-ids=true']).flags.modelIds, ['007', 'true']); +}); +test('array options without a value are rejected', () => { + const p = new CommandParser(); p.registerCommand(command); assert.match(p.validateFlags(p.parse(['build', '--models']).flags, command).join(' '), /needs a value/); +}); diff --git a/v3/@claude-flow/cli/src/parser.ts b/v3/@claude-flow/cli/src/parser.ts index 026d18034e..4810f85262 100644 --- a/v3/@claude-flow/cli/src/parser.ts +++ b/v3/@claude-flow/cli/src/parser.ts @@ -209,7 +209,7 @@ export class CommandParser { break; } - const { aliases, booleanFlags, stringFlags } = this.getFlagScope(resolvedCommands); + const { aliases, booleanFlags, stringFlags, arrayFlags } = this.getFlagScope(resolvedCommands); let i = 0; let parsingFlags = true; @@ -228,6 +228,14 @@ export class CommandParser { if (parsingFlags && arg.startsWith('-')) { const parseResult = this.parseFlag(args, i, aliases, booleanFlags, stringFlags); + // Array declarations retain text and accumulate repeated occurrences. + for (const key of arrayFlags) { + const value = parseResult.flags[key]; + if (value !== undefined && value !== true && value !== false) { + const previous = result.flags[key]; + parseResult.flags[key] = [...(Array.isArray(previous) ? previous : []), String(value)]; + } + } // Apply to result flags Object.assign(result.flags, parseResult.flags); i = parseResult.nextIndex; @@ -521,6 +529,7 @@ export class CommandParser { aliases: Record; booleanFlags: Set; stringFlags: Set; + arrayFlags: Set; } { const aliases = this.buildScopedAliases(commands[commands.length - 1]); const booleanFlags = this.getScopedBooleanFlags(commands[commands.length - 1]); @@ -530,18 +539,22 @@ export class CommandParser { if (option.short) aliases[option.short] = option.name; } } + const arrayFlags = new Set((this.options.arrayFlags ?? []).map(flag => this.normalizeKey(flag))); + for (const flag of arrayFlags) stringFlags.add(flag); const layers = [this.globalOptions, ...commands.map(command => command.options ?? [])]; for (const options of layers) { for (const option of options) { const key = this.normalizeKey(option.name); - if (option.type === 'string') stringFlags.add(key); + if (option.type === 'array') arrayFlags.add(key); + else if (option.type) arrayFlags.delete(key); + if (option.type === 'string' || option.type === 'array') stringFlags.add(key); else if (option.type) stringFlags.delete(key); if (option.type === 'boolean') booleanFlags.add(key); else if (option.type) booleanFlags.delete(key); } } for (const flag of stringFlags) booleanFlags.delete(flag); - return { aliases, booleanFlags, stringFlags }; + return { aliases, booleanFlags, stringFlags, arrayFlags }; } private getBooleanFlags(): Set { @@ -636,7 +649,7 @@ export class CommandParser { // followed by another flag) is parsed as boolean `true`. Commands then treat `true` as // the value: `hooks route --task` crashed with "task.trim is not a function" and // `memory retrieve --key` looked up the key "true". Report it instead. - if ((opt.type === 'string' || opt.type === 'number') && flags[key] === true) { + if ((opt.type === 'string' || opt.type === 'number' || opt.type === 'array') && flags[key] === true) { errors.push(`Option --${opt.name} needs a value`); } From 19e730bd54cc22685b01081b73850bdcb2ee2ee7 Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Sat, 10 Oct 2026 15:34:58 -0400 Subject: [PATCH 2/2] test: run focused regressions with the repository Vitest runner Signed-off-by: Rudy Celekli --- tests/parser-array-options.test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/parser-array-options.test.mjs b/tests/parser-array-options.test.mjs index 07d94ea82a..fc3e5ae5ce 100644 --- a/tests/parser-array-options.test.mjs +++ b/tests/parser-array-options.test.mjs @@ -1,4 +1,4 @@ -import test from 'node:test'; +import { test } from 'vitest'; import assert from 'node:assert/strict'; import { CommandParser } from '../v3/@claude-flow/cli/src/parser.ts'; const command = { name: 'build', description: '', options: [{ name: 'models', short: 'm', description: '', type: 'array' }] };