MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / parseTestArgs

Function parseTestArgs

cli/src/__tests__/cli-args.test.ts:15–52  ·  view source on GitHub ↗
(args: string[])

Source from the content-addressed store, hash-verified

13 })
14
15 function parseTestArgs(args: string[]) {
16 process.argv = ['node', 'codecane', ...args]
17
18 const program = new Command()
19 program
20 .name('codecane')
21 .version('1.0.0', '-v, --version', 'Print the CLI version')
22 .option('--agent <agent-id>', 'Specify which agent to use')
23 .option('--clear-logs', 'Remove any existing CLI log files')
24 .argument('[prompt...]', 'Initial prompt to send')
25 .allowExcessArguments(true)
26 .exitOverride() // Prevent process.exit in tests
27
28 try {
29 program.parse(process.argv)
30 } catch (error) {
31 // Commander throws on --help, --version in exitOverride mode
32 if (error instanceof Error && error.message.includes('(outputHelp)')) {
33 return { help: true }
34 }
35 if (
36 error instanceof Error &&
37 (error.message.includes('(version)') || error.message.includes('1.0.0'))
38 ) {
39 return { version: true }
40 }
41 throw error
42 }
43
44 const options = program.opts()
45 const promptArgs = program.args
46
47 return {
48 agent: options.agent,
49 clearLogs: options.clearLogs || false,
50 initialPrompt: promptArgs.length > 0 ? promptArgs.join(' ') : null,
51 }
52 }
53
54 test('parses --agent flag correctly', () => {
55 const result = parseTestArgs([

Callers 1

cli-args.test.tsFile · 0.85

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected