MCPcopy
hub / github.com/lobehub/lobehub / registerDocCommand

Function registerDocCommand

apps/cli/src/commands/doc.ts:25–371  ·  view source on GitHub ↗
(program: Command)

Source from the content-addressed store, hash-verified

23// ── Command Registration ───────────────────────────────────
24
25export function registerDocCommand(program: Command) {
26 const doc = program.command('doc').description('Manage documents');
27
28 // ── list ──────────────────────────────────────────────
29
30 doc
31 .command('list')
32 .description('List documents')
33 .option('-L, --limit <n>', 'Maximum number of items to fetch', '30')
34 .option('--file-type <type>', 'Filter by file type')
35 .option('--source-type <type>', 'Filter by source type (file, web, api, topic)')
36 .option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)')
37 .action(
38 async (options: {
39 fileType?: string;
40 json?: string | boolean;
41 limit?: string;
42 sourceType?: string;
43 }) => {
44 const client = await getTrpcClient();
45 const pageSize = Number.parseInt(options.limit || '30', 10);
46
47 const query: { fileTypes?: string[]; pageSize: number; sourceTypes?: string[] } = {
48 pageSize,
49 };
50 if (options.fileType) query.fileTypes = [options.fileType];
51 if (options.sourceType) query.sourceTypes = [options.sourceType];
52 const result = await client.document.queryDocuments.query(query);
53 const docs = Array.isArray(result) ? result : ((result as any).items ?? []);
54
55 if (options.json !== undefined) {
56 const fields = typeof options.json === 'string' ? options.json : undefined;
57 outputJson(docs, fields);
58 return;
59 }
60
61 if (docs.length === 0) {
62 console.log('No documents found.');
63 return;
64 }
65
66 const rows = docs.map((d: any) => [
67 d.id,
68 truncate(d.title || d.filename || 'Untitled', 120),
69 d.fileType || '',
70 d.updatedAt ? timeAgo(d.updatedAt) : '',
71 ]);
72
73 printTable(rows, ['ID', 'TITLE', 'TYPE', 'UPDATED']);
74 },
75 );
76
77 // ── view ──────────────────────────────────────────────
78
79 doc
80 .command('view <id>')
81 .description('View a document')
82 .option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)')

Callers 2

createProgramFunction · 0.90
createProgramFunction · 0.90

Calls 11

getTrpcClientFunction · 0.90
outputJsonFunction · 0.90
truncateFunction · 0.90
timeAgoFunction · 0.90
printTableFunction · 0.90
confirmFunction · 0.90
readBodyContentFunction · 0.85
logMethod · 0.80
parseMethod · 0.80
queryMethod · 0.45
pushMethod · 0.45

Tested by 1

createProgramFunction · 0.72