Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(cli): honor declared array option values

Rudy Celekli77632096bd99
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<string, string>;
booleanFlags: Set<string>;
stringFlags: Set<string>;
+ arrayFlags: Set<string>;
} {
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<string> {
@@ -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`);
}