mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-29 00:56:50 +00:00
feat: Add positional argument for prompt (#7668)
This commit is contained in:
@@ -1971,3 +1971,55 @@ describe('loadCliConfig fileFiltering', () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('parseArguments with positional prompt', () => {
|
||||
const originalArgv = process.argv;
|
||||
|
||||
afterEach(() => {
|
||||
process.argv = originalArgv;
|
||||
});
|
||||
|
||||
it('should throw an error when both a positional prompt and the --prompt flag are used', async () => {
|
||||
process.argv = [
|
||||
'node',
|
||||
'script.js',
|
||||
'positional',
|
||||
'prompt',
|
||||
'--prompt',
|
||||
'test prompt',
|
||||
];
|
||||
|
||||
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => {
|
||||
throw new Error('process.exit called');
|
||||
});
|
||||
|
||||
const mockConsoleError = vi
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(() => {});
|
||||
|
||||
await expect(parseArguments({} as Settings)).rejects.toThrow(
|
||||
'process.exit called',
|
||||
);
|
||||
|
||||
expect(mockConsoleError).toHaveBeenCalledWith(
|
||||
expect.stringContaining(
|
||||
'Cannot use both a positional prompt and the --prompt (-p) flag together',
|
||||
),
|
||||
);
|
||||
|
||||
mockExit.mockRestore();
|
||||
mockConsoleError.mockRestore();
|
||||
});
|
||||
|
||||
it('should correctly parse a positional prompt', async () => {
|
||||
process.argv = ['node', 'script.js', 'positional', 'prompt'];
|
||||
const argv = await parseArguments({} as Settings);
|
||||
expect(argv.promptWords).toEqual(['positional', 'prompt']);
|
||||
});
|
||||
|
||||
it('should correctly parse a prompt from the --prompt flag', async () => {
|
||||
process.argv = ['node', 'script.js', '--prompt', 'test prompt'];
|
||||
const argv = await parseArguments({} as Settings);
|
||||
expect(argv.prompt).toBe('test prompt');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user