// `node9 telemetry on | off | status` (fw#503), plus the hidden `ping` the hook // starts once a day. import type { Command } from 'commander'; const REASON: Record = { env: 'off: NODE9_NO_TELEMETRY or DO_NOT_TRACK is set', ci: 'off: running in CI', off: 'off: turned off with node9 telemetry off', 'never-shown': 'off: this install predates the usage notice. Turn on with: node9 telemetry on', }; export function registerTelemetryCommand(program: Command): void { const cmd = program .command('telemetry') .description('Show or change the anonymous usage count (on | off | status)'); cmd .command('status', { isDefault: true }) .description('Say whether the usage count is sent, and what it holds') .action(async () => { const { telemetryStatus, TELEMETRY_NOTICE } = await import('../../telemetry.js'); const s = telemetryStatus(); console.log(`Usage count: ${s.on ? 'on' : REASON[s.reason]}`); console.log(TELEMETRY_NOTICE); }); cmd .command('off') .description('Stop sending the usage count from this machine') .action(async () => { const { writeTelemetryChoice } = await import('../../telemetry.js'); writeTelemetryChoice('off'); console.log('Usage count: off. Nothing more is sent from this machine.'); }); cmd .command('on') .description('Send the anonymous usage count from this machine') .action(async () => { const { writeTelemetryChoice, telemetryStatus } = await import('../../telemetry.js'); writeTelemetryChoice('on'); const s = telemetryStatus(); console.log(s.on ? 'Usage count: on.' : `Usage count: on here, but ${REASON[s.reason]}`); }); // Started detached by the hook on the first tool call of a UTC day. Sends // `daily_active` if telemetry is on; prints nothing either way. cmd .command('ping', { hidden: true }) .description('Send the daily usage count (used by the hook)') .action(async () => { const { sendTelemetry } = await import('../../telemetry.js'); await sendTelemetry('daily_active'); }); }