Reject positional prompt with --prompt-interactive

This commit is contained in:
AshwinSaklecha 2026-03-14 12:15:32 +05:30
parent 5bcb6b619d
commit 23a535c2e2
2 changed files with 39 additions and 0 deletions

View file

@ -3278,6 +3278,42 @@ describe('parseArguments with positional prompt', () => {
debugErrorSpy.mockRestore();
});
it('should throw an error when both a positional prompt and the --prompt-interactive flag are used', async () => {
process.argv = [
'node',
'script.js',
'positional',
'prompt',
'--prompt-interactive',
'interactive prompt',
];
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit called');
});
const mockConsoleError = vi
.spyOn(console, 'error')
.mockImplementation(() => {});
const debugErrorSpy = vi
.spyOn(debugLogger, 'error')
.mockImplementation(() => {});
await expect(parseArguments(createTestMergedSettings())).rejects.toThrow(
'process.exit called',
);
expect(debugErrorSpy).toHaveBeenCalledWith(
expect.stringContaining(
'Cannot use both a positional prompt and the --prompt-interactive (-i) flag together',
),
);
mockExit.mockRestore();
mockConsoleError.mockRestore();
debugErrorSpy.mockRestore();
});
it('should correctly parse a positional prompt to query field', async () => {
process.argv = ['node', 'script.js', 'positional', 'prompt'];
const argv = await parseArguments(createTestMergedSettings());

View file

@ -236,6 +236,9 @@ export async function parseArguments(
if (argv['prompt'] && hasPositionalQuery) {
return 'Cannot use both a positional prompt and the --prompt (-p) flag together';
}
if (argv['promptInteractive'] !== undefined && hasPositionalQuery) {
return 'Cannot use both a positional prompt and the --prompt-interactive (-i) flag together';
}
if (argv['prompt'] && argv['promptInteractive']) {
return 'Cannot use both --prompt (-p) and --prompt-interactive (-i) together';
}