From 86ab0b23481e50251bb78e472fdc52d0b4551bad Mon Sep 17 00:00:00 2001 From: Yinchaochen Date: Wed, 29 Apr 2026 23:21:25 +0200 Subject: [PATCH] fix: allow dash-leading positional adapter args --- src/commanderAdapter.test.ts | 17 +++++++++++++++++ src/commanderAdapter.ts | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/src/commanderAdapter.test.ts b/src/commanderAdapter.test.ts index 48ecc723f..d52c6619d 100644 --- a/src/commanderAdapter.test.ts +++ b/src/commanderAdapter.test.ts @@ -84,6 +84,23 @@ describe('commanderAdapter arg passing', () => { }); }); + it('accepts dash-leading positional arguments while still parsing later options', async () => { + const program = new Command(); + program.exitOverride(); + const siteCmd = program.command('paperreview'); + registerCommandToProgram(siteCmd, cmd); + + await program.parseAsync(['node', 'opencli', 'paperreview', 'submit', '-123456abdc', '-f', 'json']); + + expect(mockExecuteCommand).toHaveBeenCalled(); + const kwargs = mockExecuteCommand.mock.calls[0][1]; + expect(kwargs.pdf).toBe('-123456abdc'); + expect(mockRenderOutput).toHaveBeenCalledWith( + [], + expect.objectContaining({ fmt: 'json' }), + ); + }); + it('rejects invalid bool values before calling executeCommand', async () => { const program = new Command(); const siteCmd = program.command('paperreview'); diff --git a/src/commanderAdapter.ts b/src/commanderAdapter.ts index 47b98c35f..8e5a3eec6 100644 --- a/src/commanderAdapter.ts +++ b/src/commanderAdapter.ts @@ -33,6 +33,11 @@ export function registerCommandToProgram(siteCmd: Command, cmd: CliCommand): voi const deprecatedSuffix = cmd.deprecated ? ' [deprecated]' : ''; const subCmd = siteCmd.command(cmd.name).description(`${cmd.description}${deprecatedSuffix}`); if (cmd.aliases?.length) subCmd.aliases(cmd.aliases); + const hasPositionalArgs = cmd.args.some((arg) => arg.positional); + + // Commander treats dash-leading positional values as unknown options by default. + // Allow them through so our adapter layer can validate values like "-123456abdc". + if (hasPositionalArgs) subCmd.allowUnknownOption(); // Register positional args first, then named options const positionalArgs: typeof cmd.args = [];