Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/cli/commands/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { Command } from 'commander';
import chalk from 'chalk';
import inquirer from 'inquirer';
import { AnalyticsAggregator } from './aggregator.js';
import { AnalyticsFormatter } from './formatter.js';
import { AnalyticsExporter } from './exporter.js';
Expand Down Expand Up @@ -150,6 +151,26 @@ export async function runAnalytics(options: AnalyticsOptions, source: AnalyticsS
// omit email gracefully
}

if (userEmail === undefined && process.stdout.isTTY) {
console.log(chalk.yellow('\n Warning: your email is not configured. It will be included in the report metadata and saved for future runs.'));
try {
const { email } = await inquirer.prompt<{ email: string }>([{
type: 'input',
name: 'email',
message: 'Enter your email address:',
validate: (v: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v.trim()) || 'Please enter a valid email address',
}]);
userEmail = email.trim();
await ConfigLoader.saveUserEmail(userEmail).catch(() => { /* non-fatal */ });
} catch (err) {
if (err instanceof Error && (err.name === 'ExitPromptError' || err.name === 'AbortPromptError')) {
console.log(chalk.dim('\n Report generation cancelled.'));
return;
}
throw err;
}
}

const { index: costIndex, summary } = costResult;
const payload = buildPayload(analytics, costIndex, summary, {
rangeLabel: options.last ?? (options.from || options.to ? 'custom' : 'all'),
Expand Down
Loading