Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/commanderAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions src/commanderAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down