diff --git a/packages/core/src/command/parser.ts b/packages/core/src/command/parser.ts index 44c9f0421..b541c9ca4 100644 --- a/packages/core/src/command/parser.ts +++ b/packages/core/src/command/parser.ts @@ -426,6 +426,11 @@ export namespace Argv { } const name = content.slice(i, j) if (this.config.strictOptions && !this._namedOptions[name]) { + if (this.ctx.$commander.resolveDomain(argDecl.type).greedy) { + argv.tokens.unshift(token) + args.push(this.ctx.$commander.parseValue(Argv.stringify(argv), 'argument', argv, argDecl)) + break + } args.push(this.ctx.$commander.parseValue(content, 'argument', argv, argDecl)) continue } diff --git a/packages/core/tests/parser.spec.ts b/packages/core/tests/parser.spec.ts index 369901f04..eedd6e428 100644 --- a/packages/core/tests/parser.spec.ts +++ b/packages/core/tests/parser.spec.ts @@ -95,6 +95,12 @@ describe('Parser API', () => { expect(cmd.parse('-c')).to.have.shape({ options: { gamma: 1 } }) }) + it('greedy + strict options', () => { + // https://github.com/koishijs/koishi/issues/1473 + cmd = app.command('test-greedy-strict [foo:text]', { strictOptions: true }) + expect(cmd.parse('-a -b -c')).to.have.shape({ args: ['-a -b -c'] }) + }) + it('valued options', () => { cmd = app.command('cmd2 [bar:text]') cmd.option('alpha', '-A, --no-alpha', { value: false })