MCPcopy Create free account
hub / github.com/ChromeDevTools/chrome-devtools-mcp / parseToolCommand

Function parseToolCommand

tests/cli.test.ts:1540–1583  ·  view source on GitHub ↗
(rawArgs: string[])

Source from the content-addressed store, hash-verified

1538 };
1539
1540 function parseToolCommand(rawArgs: string[]): Record<string, unknown> {
1541 const {argv: cliArgs, restore} = shieldLiteralArgs(rawArgs, commandName => {
1542 const commandDef = mockCommands[commandName];
1543 return commandDef ? getCommandArgSpec(commandDef.args) : undefined;
1544 });
1545
1546 let parsedArgs: Record<string, unknown> | undefined;
1547 const parser = yargs(cliArgs)
1548 .locale('en')
1549 .exitProcess(false)
1550 .strict()
1551 .fail((msg, err) => {
1552 throw err ?? new Error(msg);
1553 });
1554
1555 for (const [commandName, commandDef] of Object.entries(mockCommands)) {
1556 const {command, usage} = buildCommand(commandName, commandDef.args);
1557 parser.command(
1558 command,
1559 commandDef.description,
1560 y => {
1561 y.usage(usage);
1562 y.option('output-format', {
1563 choices: ['md', 'json'],
1564 default: 'md',
1565 });
1566 registerCommandArgs(y, commandDef.args);
1567 },
1568 argv => {
1569 const commandArgs: Record<string, unknown> = {};
1570 for (const argName of Object.keys(commandDef.args)) {
1571 if (argName in argv) {
1572 commandArgs[argName] = restore(argv[argName]);
1573 }
1574 }
1575 parsedArgs = commandArgs;
1576 },
1577 );
1578 }
1579
1580 parser.parse();
1581 assert.ok(parsedArgs, `Command did not match: ${rawArgs.join(' ')}`);
1582 return parsedArgs;
1583 }
1584
1585 it('parses an omitted variadic array arg without minItems as an empty array', () => {
1586 assert.deepStrictEqual(parseToolCommand(['allow_empty_array', '2']), {

Callers 1

cli.test.tsFile · 0.85

Calls 7

shieldLiteralArgsFunction · 0.85
getCommandArgSpecFunction · 0.85
buildCommandFunction · 0.85
registerCommandArgsFunction · 0.85
restoreFunction · 0.85
failMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected