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

Function computeFlagUsage

src/telemetry/flagUtils.ts:39–71  ·  view source on GitHub ↗
(
  args: Record<string, unknown>,
  options: CliOptions,
)

Source from the content-addressed store, hash-verified

37 * IMPORTANT: keep getPossibleFlagMetrics() in sync with this function.
38 */
39export function computeFlagUsage(
40 args: Record<string, unknown>,
41 options: CliOptions,
42): FlagUsage {
43 const usage: FlagUsage = {};
44
45 for (const [flagName, config] of Object.entries(options)) {
46 const value = args[flagName];
47 const snakeCaseName = stripUnderscoreBeforeNumber(toSnakeCase(flagName));
48
49 // If there isn't a default value provided for the flag,
50 // we're going to log whether it's present on the args user
51 // provided or not. If there is a default value, we only log presence
52 // if the value differs from the default, implying explicit user intent.
53 if (!('default' in config) || value !== config.default) {
54 usage[`${snakeCaseName}_present`] = value !== undefined && value !== null;
55 }
56
57 if (config.type === 'boolean' && typeof value === 'boolean') {
58 // For boolean options, we're going to log the value directly.
59 usage[snakeCaseName] = value;
60 } else if (
61 config.type === 'string' &&
62 typeof value === 'string' &&
63 'choices' in config &&
64 config.choices
65 ) {
66 usage[snakeCaseName] = formatEnumChoice(snakeCaseName, value);
67 }
68 }
69
70 return usage;
71}
72
73export interface FlagMetric {
74 name: string;

Callers 2

flagUtils.test.tsFile · 0.85

Calls 3

toSnakeCaseFunction · 0.85
formatEnumChoiceFunction · 0.85

Tested by

no test coverage detected