Skip to content

Commit c318422

Browse files
authored
chore(cli): introduce telemetry and opt-out options (#107)
* chore: use barrel file * chore(core): flush telemetry * feat(cli): introduce `telemetry` and opt-out options
1 parent 7506356 commit c318422

38 files changed

Lines changed: 130 additions & 71 deletions

‎packages/cli/bin/cli.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import yargs from 'yargs';
44
import { hideBin } from 'yargs/helpers';
5+
import { APP_NAME, CLI_VERSION } from '@meta';
6+
import { flushTelemetry, telemetryMiddleware } from '@utils/index.js';
57
import {
68
loginCommand,
79
logoutCommand,
@@ -18,7 +20,6 @@ import {
1820
pluginCommand,
1921
migrateCommand,
2022
} from '../src/commands/index.js';
21-
import { APP_NAME, CLI_VERSION } from '@meta';
2223

2324
const cli = yargs(hideBin(process.argv))
2425
.scriptName(APP_NAME)
@@ -65,6 +66,12 @@ const cli = yargs(hideBin(process.argv))
6566
describe: 'Verbose/diagnostic output',
6667
hidden: true,
6768
})
69+
.option('telemetry', {
70+
type: 'boolean',
71+
default: true,
72+
describe: 'Collect anonymous usage telemetry (disable with --no-telemetry)',
73+
})
74+
.middleware(telemetryMiddleware)
6875
.command(loginCommand)
6976
.command(logoutCommand)
7077
.command(whoamiCommand)
@@ -91,4 +98,8 @@ const cli = yargs(hideBin(process.argv))
9198
.help()
9299
.version(CLI_VERSION);
93100

94-
cli.parse();
101+
try {
102+
await cli.parseAsync();
103+
} finally {
104+
await flushTelemetry();
105+
}

‎packages/cli/src/commands/docs.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Argv } from 'yargs';
22
import { searchDocs, grepDocs, readDocs } from '@features/docs/index.js';
3-
import { safely } from '../utils/safely.js';
3+
import { safely } from '@utils/index.js';
44

55
export const docsCommand = {
66
command: 'docs <action>',

‎packages/cli/src/commands/events.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
deleteEvent,
99
eventUsage,
1010
} from '@features/events/index.js';
11-
import { safely } from '../utils/safely.js';
11+
import { safely } from '@utils/index.js';
1212

1313
export const eventsCommand = {
1414
command: 'events <action>',

‎packages/cli/src/commands/flags.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
targetFlagCmd,
1111
archiveFlagCmd,
1212
} from '@features/flags/index.js';
13-
import { safely } from '../utils/safely.js';
13+
import { safely } from '@utils/index.js';
1414

1515
export const flagsCommand = {
1616
command: 'flags <action>',

‎packages/cli/src/commands/migrate.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Argv } from 'yargs';
22
import { getProviders } from '@spotify-confidence/core';
33
import { detectAndPrint, launchMigration } from '@features/migrate/index.js';
4-
import { safely } from '../utils/safely.js';
4+
import { safely } from '@utils/index.js';
55

66
export const migrateCommand = {
77
command: 'migrate <action>',

‎packages/cli/src/commands/plugin.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
uninstallPluginForIde,
1212
updatePluginForIde,
1313
} from '@features/plugin/index.js';
14-
import { safely } from '@utils/safely.js';
14+
import { safely } from '@utils/index.js';
1515

1616
export const pluginCommand = {
1717
command: 'plugin <action>',

‎packages/cli/src/commands/recordings.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import {
1010
showTargetingKeys,
1111
addTargetingKey,
1212
} from '@features/recordings/index.js';
13-
import { safely } from '../utils/safely.js';
14-
import { validateRange } from '../utils/validation.js';
13+
import { safely, validateRange } from '@utils/index.js';
1514

1615
export const recordingsCommand = {
1716
command: 'recordings <action>',

‎packages/cli/src/features/docs/grep.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ora from 'ora';
22
import { grepDocumentation } from '@network/index.js';
33
import { printMcpResult } from '@output/print.js';
4-
import { withAuth } from '@utils/require-auth.js';
4+
import { withAuth } from '@utils/index.js';
55

66
export const grepDocs = withAuth(async function grepDocs(argv, token) {
77
const pattern = argv.pattern as string;

‎packages/cli/src/features/docs/read.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ora from 'ora';
22
import { CONFIDENCE_DOCS_URL } from '@spotify-confidence/core';
33
import { getFullSource } from '@network/index.js';
44
import { printMcpResult } from '@output/print.js';
5-
import { withAuth } from '@utils/require-auth.js';
5+
import { withAuth } from '@utils/index.js';
66

77
function normalizeSource(input: string): string {
88
if (input.includes('://')) return input;

‎packages/cli/src/features/docs/search.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ora from 'ora';
22
import { searchDocumentation } from '@network/index.js';
33
import { printMcpResult } from '@output/print.js';
4-
import { withAuth } from '@utils/require-auth.js';
4+
import { withAuth } from '@utils/index.js';
55

66
export const searchDocs = withAuth(async function searchDocs(argv, token) {
77
const query = argv.query as string;

0 commit comments

Comments
 (0)