MCPcopy
hub / github.com/lobehub/lobehub / registerConfigCommand

Function registerConfigCommand

apps/cli/src/commands/config.ts:14–196  ·  view source on GitHub ↗
(program: Command)

Source from the content-addressed store, hash-verified

12} from '../utils/format';
13
14export function registerConfigCommand(program: Command) {
15 // ── whoami ────────────────────────────────────────────
16
17 program
18 .command('whoami')
19 .description('Display current user information')
20 .option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)')
21 .action(async (options: { json?: string | boolean }) => {
22 const client = await getTrpcClient();
23 const state = await client.user.getUserState.query();
24
25 if (options.json !== undefined) {
26 const fields = typeof options.json === 'string' ? options.json : undefined;
27 outputJson(state, fields);
28 return;
29 }
30
31 const s = state as any;
32 console.log(pc.bold('User Info'));
33 if (s.fullName || s.firstName) console.log(` Name: ${s.fullName || s.firstName}`);
34 if (s.username) console.log(` Username: ${s.username}`);
35 if (s.email) console.log(` Email: ${s.email}`);
36 if (s.userId) console.log(` User ID: ${s.userId}`);
37 if (s.subscriptionPlan) console.log(` Plan: ${s.subscriptionPlan}`);
38 });
39
40 // ── usage ─────────────────────────────────────────────
41
42 program
43 .command('usage')
44 .description('View usage statistics')
45 .option('--month <YYYY-MM>', 'Month to query (default: current)')
46 .option('--daily', 'Group by day')
47 .option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)')
48 .action(async (options: { daily?: boolean; json?: string | boolean; month?: string }) => {
49 const client = await getTrpcClient();
50
51 const input: { mo?: string } = {};
52 if (options.month) input.mo = options.month;
53
54 if (options.json !== undefined) {
55 let jsonResult: any;
56 if (options.daily) {
57 jsonResult = await client.usage.findAndGroupByDay.query(input);
58 } else {
59 jsonResult = await client.usage.findByMonth.query(input);
60 }
61 const fields = typeof options.json === 'string' ? options.json : undefined;
62 outputJson(jsonResult, fields);
63 return;
64 }
65
66 // Always fetch daily-grouped data for table display
67 const result: any = await client.usage.findAndGroupByDay.query(input);
68
69 if (!result) {
70 console.log('No usage data available.');
71 return;

Callers 2

createProgramFunction · 0.90
createProgramFunction · 0.90

Calls 11

getTrpcClientFunction · 0.90
outputJsonFunction · 0.90
formatCostFunction · 0.90
formatNumberFunction · 0.90
printBoxTableFunction · 0.90
printCalendarHeatmapFunction · 0.90
logMethod · 0.80
addMethod · 0.80
sortMethod · 0.80
queryMethod · 0.45
pushMethod · 0.45

Tested by 1

createProgramFunction · 0.72