@refhub/cli 1.8.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +16 -0
- package/dist/client.js +103 -59
- package/dist/commands/audit.js +5 -6
- package/dist/commands/discover.js +19 -25
- package/dist/commands/enrich.js +35 -38
- package/dist/commands/export.js +6 -8
- package/dist/commands/import.js +16 -22
- package/dist/commands/inbox.js +43 -56
- package/dist/commands/items.js +48 -64
- package/dist/commands/pdf.js +6 -8
- package/dist/commands/relations.js +17 -21
- package/dist/commands/relationsScan.js +45 -49
- package/dist/commands/sections.js +17 -21
- package/dist/commands/tags.js +25 -31
- package/dist/commands/vaults.js +47 -60
- package/dist/format.js +15 -0
- package/package.json +1 -1
package/dist/commands/import.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/commands/import.ts
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
|
-
import {
|
|
3
|
+
import { UsageError, action } from '../client.js';
|
|
4
4
|
import { format } from '../format.js';
|
|
5
5
|
function parseTags(tagsCsv) {
|
|
6
6
|
if (!tagsCsv)
|
|
@@ -27,11 +27,10 @@ export function registerImport(program) {
|
|
|
27
27
|
.requiredOption('--vault <id>')
|
|
28
28
|
.requiredOption('--doi <doi>')
|
|
29
29
|
.option('--tags <ids>', 'comma-separated tag IDs to attach')
|
|
30
|
-
.action(async (opts,
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
30
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
31
|
+
const client = getClient();
|
|
32
|
+
await handleImportDoi(client, opts.vault, opts.doi, opts.tags, g.table ?? false);
|
|
33
|
+
}));
|
|
35
34
|
imp
|
|
36
35
|
.command('bibtex')
|
|
37
36
|
.description('Import references from a BibTeX string or file')
|
|
@@ -39,36 +38,31 @@ export function registerImport(program) {
|
|
|
39
38
|
.option('--bibtex <string>', 'inline BibTeX string')
|
|
40
39
|
.option('--file <path>', 'path to .bib file')
|
|
41
40
|
.option('--tags <ids>', 'comma-separated tag IDs to attach')
|
|
42
|
-
.action(async (opts,
|
|
43
|
-
const g = cmd.optsWithGlobals();
|
|
41
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
44
42
|
if (!opts.bibtex && !opts.file) {
|
|
45
|
-
|
|
46
|
-
process.exit(2);
|
|
43
|
+
throw new UsageError('missing_input', 'Provide --bibtex <string> or --file <path>.');
|
|
47
44
|
}
|
|
48
45
|
if (opts.bibtex && opts.file) {
|
|
49
|
-
|
|
50
|
-
process.exit(2);
|
|
46
|
+
throw new UsageError('conflicting_input', 'Pass --bibtex <string> or --file <path>, not both.');
|
|
51
47
|
}
|
|
52
48
|
let bibtex;
|
|
53
49
|
try {
|
|
54
50
|
bibtex = opts.file ? readFileSync(opts.file, 'utf8') : opts.bibtex;
|
|
55
51
|
}
|
|
56
52
|
catch (e) {
|
|
57
|
-
|
|
58
|
-
process.exit(2);
|
|
53
|
+
throw new UsageError('file_read_error', `Cannot read file: ${String(e)}`);
|
|
59
54
|
}
|
|
60
|
-
const client =
|
|
61
|
-
await
|
|
62
|
-
});
|
|
55
|
+
const client = getClient();
|
|
56
|
+
await handleImportBibtex(client, opts.vault, bibtex, opts.tags, g.table ?? false);
|
|
57
|
+
}));
|
|
63
58
|
imp
|
|
64
59
|
.command('url')
|
|
65
60
|
.description('Import a reference from a URL (Open Graph scrape)')
|
|
66
61
|
.requiredOption('--vault <id>')
|
|
67
62
|
.requiredOption('--url <url>')
|
|
68
63
|
.option('--tags <ids>', 'comma-separated tag IDs to attach')
|
|
69
|
-
.action(async (opts,
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
});
|
|
64
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
65
|
+
const client = getClient();
|
|
66
|
+
await handleImportUrl(client, opts.vault, opts.url, opts.tags, g.table ?? false);
|
|
67
|
+
}));
|
|
74
68
|
}
|
package/dist/commands/inbox.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/commands/inbox.ts
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
|
-
import {
|
|
3
|
+
import { UsageError, action } from '../client.js';
|
|
4
4
|
import { format } from '../format.js';
|
|
5
5
|
export async function handleInboxList(client, opts, tableMode) {
|
|
6
6
|
const result = await client.listInbox(opts);
|
|
@@ -25,16 +25,14 @@ export async function handleInboxAccept(client, itemId, vaultId, tagsCsv, tableM
|
|
|
25
25
|
}
|
|
26
26
|
export async function handleInboxReject(client, itemId, confirmed) {
|
|
27
27
|
if (!confirmed) {
|
|
28
|
-
|
|
29
|
-
process.exit(2);
|
|
28
|
+
throw new UsageError('confirm_required', 'Pass --confirm to acknowledge there is no way to un-reject an inbox item.');
|
|
30
29
|
}
|
|
31
30
|
const result = await client.rejectInboxItem(itemId);
|
|
32
31
|
format(result, false);
|
|
33
32
|
}
|
|
34
33
|
export async function handleInboxMerge(client, itemId, confirmed, tableMode) {
|
|
35
34
|
if (!confirmed) {
|
|
36
|
-
|
|
37
|
-
process.exit(2);
|
|
35
|
+
throw new UsageError('confirm_required', 'Pass --confirm to acknowledge there is no way to un-merge an inbox item.');
|
|
38
36
|
}
|
|
39
37
|
const result = await client.mergeInboxItem(itemId);
|
|
40
38
|
format(result, tableMode);
|
|
@@ -45,8 +43,7 @@ export async function handleInboxPostpone(client, itemId, tableMode) {
|
|
|
45
43
|
}
|
|
46
44
|
export async function handleInboxDelete(client, itemId, confirmed) {
|
|
47
45
|
if (!confirmed) {
|
|
48
|
-
|
|
49
|
-
process.exit(2);
|
|
46
|
+
throw new UsageError('confirm_required', 'Pass --confirm to acknowledge this is a hard delete with no undo.');
|
|
50
47
|
}
|
|
51
48
|
const result = await client.deleteInboxItem(itemId);
|
|
52
49
|
format(result, false);
|
|
@@ -58,102 +55,92 @@ export function registerInbox(program) {
|
|
|
58
55
|
.description('List pending inbox items')
|
|
59
56
|
.option('--page <n>', 'page number', (v) => parseInt(v, 10))
|
|
60
57
|
.option('--limit <n>', 'results per page (server default 50, max 200)', (v) => parseInt(v, 10))
|
|
61
|
-
.action(async (opts,
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
58
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
59
|
+
const client = getClient();
|
|
60
|
+
await handleInboxList(client, { page: opts.page, limit: opts.limit }, g.table ?? false);
|
|
61
|
+
}));
|
|
66
62
|
const capture = inbox.command('capture').description('Capture a paper into the inbox');
|
|
67
63
|
capture
|
|
68
64
|
.command('doi')
|
|
69
65
|
.description('Capture by DOI')
|
|
70
66
|
.argument('<doi>')
|
|
71
|
-
.action(async (doi,
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
67
|
+
.action(action(async ({ args: [doi], g, getClient }) => {
|
|
68
|
+
const client = getClient();
|
|
69
|
+
await handleInboxCaptureDoi(client, doi, g.table ?? false);
|
|
70
|
+
}));
|
|
76
71
|
capture
|
|
77
72
|
.command('bibtex')
|
|
78
73
|
.description('Capture from a BibTeX string or file (bulk -- one inbox item per entry)')
|
|
79
74
|
.option('--bibtex <string>', 'inline BibTeX string')
|
|
80
75
|
.option('--file <path>', 'path to .bib file')
|
|
81
|
-
.action(async (opts,
|
|
82
|
-
const g = cmd.optsWithGlobals();
|
|
76
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
83
77
|
if (!opts.bibtex && !opts.file) {
|
|
84
|
-
|
|
85
|
-
process.exit(2);
|
|
78
|
+
throw new UsageError('missing_input', 'Provide --bibtex <string> or --file <path>.');
|
|
86
79
|
}
|
|
87
80
|
if (opts.bibtex && opts.file) {
|
|
88
|
-
|
|
89
|
-
process.exit(2);
|
|
81
|
+
throw new UsageError('conflicting_input', 'Pass --bibtex <string> or --file <path>, not both.');
|
|
90
82
|
}
|
|
91
83
|
let bibtex;
|
|
92
84
|
try {
|
|
93
85
|
bibtex = opts.file ? readFileSync(opts.file, 'utf8') : opts.bibtex;
|
|
94
86
|
}
|
|
95
87
|
catch (e) {
|
|
96
|
-
|
|
97
|
-
process.exit(2);
|
|
88
|
+
throw new UsageError('file_read_error', `Cannot read file: ${String(e)}`);
|
|
98
89
|
}
|
|
99
|
-
const client =
|
|
100
|
-
await
|
|
101
|
-
});
|
|
90
|
+
const client = getClient();
|
|
91
|
+
await handleInboxCaptureBibtex(client, bibtex, g.table ?? false);
|
|
92
|
+
}));
|
|
102
93
|
capture
|
|
103
94
|
.command('manual')
|
|
104
95
|
.description('Capture a manual entry (title only)')
|
|
105
96
|
.requiredOption('--title <title>')
|
|
106
|
-
.action(async (opts,
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
97
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
98
|
+
const client = getClient();
|
|
99
|
+
await handleInboxCaptureManual(client, opts.title, g.table ?? false);
|
|
100
|
+
}));
|
|
111
101
|
inbox
|
|
112
102
|
.command('accept')
|
|
113
103
|
.argument('<itemId>')
|
|
114
104
|
.description('File a pending item into a vault')
|
|
115
105
|
.requiredOption('--vault <id>')
|
|
116
106
|
.option('--tags <ids>', 'comma-separated tag IDs to attach')
|
|
117
|
-
.action(async (itemId, opts,
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
});
|
|
107
|
+
.action(action(async ({ args: [itemId], opts, g, getClient }) => {
|
|
108
|
+
const client = getClient();
|
|
109
|
+
await handleInboxAccept(client, itemId, opts.vault, opts.tags, g.table ?? false);
|
|
110
|
+
}));
|
|
122
111
|
inbox
|
|
123
112
|
.command('reject')
|
|
124
113
|
.argument('<itemId>')
|
|
125
114
|
.description('Discard a pending item (no undo)')
|
|
126
115
|
.option('--confirm', 'required: acknowledge there is no way to un-reject')
|
|
127
|
-
.action(async (itemId, opts,
|
|
128
|
-
const client =
|
|
129
|
-
await
|
|
130
|
-
});
|
|
116
|
+
.action(action(async ({ args: [itemId], opts, getClient }) => {
|
|
117
|
+
const client = getClient();
|
|
118
|
+
await handleInboxReject(client, itemId, opts.confirm ?? false);
|
|
119
|
+
}));
|
|
131
120
|
inbox
|
|
132
121
|
.command('merge')
|
|
133
122
|
.argument('<itemId>')
|
|
134
123
|
.description('File a pending item as a duplicate of the match RefHub already found (no undo)')
|
|
135
124
|
.option('--confirm', 'required: acknowledge there is no way to un-merge')
|
|
136
|
-
.action(async (itemId, opts,
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
});
|
|
125
|
+
.action(action(async ({ args: [itemId], opts, g, getClient }) => {
|
|
126
|
+
const client = getClient();
|
|
127
|
+
await handleInboxMerge(client, itemId, opts.confirm ?? false, g.table ?? false);
|
|
128
|
+
}));
|
|
141
129
|
inbox
|
|
142
130
|
.command('postpone')
|
|
143
131
|
.argument('<itemId>')
|
|
144
132
|
.description('Move a pending item to the back of the queue')
|
|
145
|
-
.action(async (itemId,
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
});
|
|
133
|
+
.action(action(async ({ args: [itemId], g, getClient }) => {
|
|
134
|
+
const client = getClient();
|
|
135
|
+
await handleInboxPostpone(client, itemId, g.table ?? false);
|
|
136
|
+
}));
|
|
150
137
|
inbox
|
|
151
138
|
.command('delete')
|
|
152
139
|
.argument('<itemId>')
|
|
153
140
|
.description('Delete an inbox item regardless of status (hard delete, no undo)')
|
|
154
141
|
.option('--confirm', 'required: acknowledge this is a permanent deletion')
|
|
155
|
-
.action(async (itemId, opts,
|
|
156
|
-
const client =
|
|
157
|
-
await
|
|
158
|
-
});
|
|
142
|
+
.action(action(async ({ args: [itemId], opts, getClient }) => {
|
|
143
|
+
const client = getClient();
|
|
144
|
+
await handleInboxDelete(client, itemId, opts.confirm ?? false);
|
|
145
|
+
}));
|
|
159
146
|
}
|
package/dist/commands/items.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// src/commands/items.ts
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
3
|
import { InvalidArgumentError } from 'commander';
|
|
4
|
-
import {
|
|
4
|
+
import { UsageError, action } from '../client.js';
|
|
5
5
|
import { format } from '../format.js';
|
|
6
6
|
function usageError(code, message) {
|
|
7
|
-
|
|
8
|
-
process.exit(2);
|
|
7
|
+
throw new UsageError(code, message);
|
|
9
8
|
}
|
|
10
9
|
/** Collects a repeatable option into an array. */
|
|
11
10
|
export function collectOption(value, previous = []) {
|
|
@@ -121,8 +120,7 @@ export async function handleItemUpdate(client, vaultId, itemId, opts, tableMode)
|
|
|
121
120
|
}
|
|
122
121
|
export async function handleItemDelete(client, vaultId, itemId, confirmed) {
|
|
123
122
|
if (!confirmed) {
|
|
124
|
-
|
|
125
|
-
process.exit(2);
|
|
123
|
+
throw new UsageError('confirm_required', 'Pass --confirm to acknowledge this is a hard delete with no undo.');
|
|
126
124
|
}
|
|
127
125
|
const result = await client.deleteItem(vaultId, itemId);
|
|
128
126
|
format(result, false);
|
|
@@ -130,8 +128,7 @@ export async function handleItemDelete(client, vaultId, itemId, confirmed) {
|
|
|
130
128
|
export async function handleItemUpsert(client, vaultId, filePath, idempotencyKey, tableMode) {
|
|
131
129
|
const items = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
132
130
|
if (!Array.isArray(items)) {
|
|
133
|
-
|
|
134
|
-
process.exit(2);
|
|
131
|
+
throw new UsageError('invalid_file', 'File must contain a JSON array of items.');
|
|
135
132
|
}
|
|
136
133
|
const result = await client.upsertItems(vaultId, items, idempotencyKey);
|
|
137
134
|
format(result, tableMode);
|
|
@@ -139,8 +136,7 @@ export async function handleItemUpsert(client, vaultId, filePath, idempotencyKey
|
|
|
139
136
|
export async function handleItemPreview(client, vaultId, filePath, tableMode) {
|
|
140
137
|
const items = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
141
138
|
if (!Array.isArray(items)) {
|
|
142
|
-
|
|
143
|
-
process.exit(2);
|
|
139
|
+
throw new UsageError('invalid_file', 'File must contain a JSON array of items.');
|
|
144
140
|
}
|
|
145
141
|
const result = await client.previewImport(vaultId, items);
|
|
146
142
|
format(result, tableMode);
|
|
@@ -173,21 +169,19 @@ export function registerItems(program) {
|
|
|
173
169
|
.requiredOption('--vault <id>')
|
|
174
170
|
.option('--page <n>', 'page number', (v) => parseInt(v, 10))
|
|
175
171
|
.option('--limit <n>', 'results per page', (v) => parseInt(v, 10))
|
|
176
|
-
.action(async (opts,
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
});
|
|
172
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
173
|
+
const client = getClient();
|
|
174
|
+
await handleItemsList(client, opts.vault, { page: opts.page, limit: opts.limit }, g.table ?? false);
|
|
175
|
+
}));
|
|
181
176
|
items
|
|
182
177
|
.command('get')
|
|
183
178
|
.argument('<itemId>')
|
|
184
179
|
.description('Get a single item')
|
|
185
180
|
.requiredOption('--vault <id>')
|
|
186
|
-
.action(async (itemId, opts,
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
});
|
|
181
|
+
.action(action(async ({ args: [itemId], opts, g, getClient }) => {
|
|
182
|
+
const client = getClient();
|
|
183
|
+
await handleItemGet(client, opts.vault, itemId, g.table ?? false);
|
|
184
|
+
}));
|
|
191
185
|
items
|
|
192
186
|
.command('add')
|
|
193
187
|
.description('Add an item to a vault')
|
|
@@ -201,11 +195,10 @@ export function registerItems(program) {
|
|
|
201
195
|
.option('--tags <ids>', 'comma-separated tag IDs')
|
|
202
196
|
.option('--notes <text>', 'free-text notes on the item')
|
|
203
197
|
.option('--pdf-url <url>', "publisher PDF link (the frontend's publisher_pdf field)")
|
|
204
|
-
.action(async (opts,
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
});
|
|
198
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
199
|
+
const client = getClient();
|
|
200
|
+
await handleItemAdd(client, opts.vault, { title: opts.title, author: opts.author, authors: opts.authors, year: opts.year, doi: opts.doi, url: opts.url, tags: opts.tags, notes: opts.notes, pdfUrl: opts.pdfUrl }, g.table ?? false);
|
|
201
|
+
}));
|
|
209
202
|
items
|
|
210
203
|
.command('update')
|
|
211
204
|
.argument('<itemId>')
|
|
@@ -225,54 +218,48 @@ export function registerItems(program) {
|
|
|
225
218
|
.option('--featured', 'mark this item as featured — requires vault owner access')
|
|
226
219
|
.option('--unfeature', 'remove this item from featured — requires vault owner access')
|
|
227
220
|
.option('--featured-note <text>', 'curator note shown alongside the featured item — requires vault owner access')
|
|
228
|
-
.action(async (itemId, opts,
|
|
221
|
+
.action(action(async ({ args: [itemId], opts, g, getClient }) => {
|
|
229
222
|
if (opts.section && opts.unsetSection) {
|
|
230
|
-
|
|
231
|
-
process.exit(2);
|
|
223
|
+
throw new UsageError('invalid_options', 'Pass at most one of --section or --unset-section.');
|
|
232
224
|
}
|
|
233
225
|
if (opts.featured && opts.unfeature) {
|
|
234
|
-
|
|
235
|
-
process.exit(2);
|
|
226
|
+
throw new UsageError('invalid_options', 'Pass at most one of --featured or --unfeature.');
|
|
236
227
|
}
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
await run(() => handleItemUpdate(client, opts.vault, itemId, {
|
|
228
|
+
const client = getClient();
|
|
229
|
+
await handleItemUpdate(client, opts.vault, itemId, {
|
|
240
230
|
title: opts.title, author: opts.author, authors: opts.authors, year: opts.year, doi: opts.doi, url: opts.url, tags: opts.tags, notes: opts.notes, pdfUrl: opts.pdfUrl,
|
|
241
231
|
section: opts.section, unsetSection: opts.unsetSection, featured: opts.featured, unfeature: opts.unfeature, featuredNote: opts.featuredNote,
|
|
242
|
-
}, g.table ?? false)
|
|
243
|
-
});
|
|
232
|
+
}, g.table ?? false);
|
|
233
|
+
}));
|
|
244
234
|
items
|
|
245
235
|
.command('delete')
|
|
246
236
|
.argument('<itemId>')
|
|
247
237
|
.description('Delete an item (hard delete, no undo)')
|
|
248
238
|
.requiredOption('--vault <id>')
|
|
249
239
|
.option('--confirm', 'required: acknowledge permanent deletion')
|
|
250
|
-
.action(async (itemId, opts,
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
});
|
|
240
|
+
.action(action(async ({ args: [itemId], opts, g, getClient }) => {
|
|
241
|
+
const client = getClient();
|
|
242
|
+
await handleItemDelete(client, opts.vault, itemId, opts.confirm ?? false);
|
|
243
|
+
}));
|
|
255
244
|
items
|
|
256
245
|
.command('upsert')
|
|
257
246
|
.description('Bulk upsert items from a JSON file')
|
|
258
247
|
.requiredOption('--vault <id>')
|
|
259
248
|
.requiredOption('--file <path>', 'path to JSON file containing array of items')
|
|
260
249
|
.option('--idempotency-key <key>', 'safe retry key')
|
|
261
|
-
.action(async (opts,
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
});
|
|
250
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
251
|
+
const client = getClient();
|
|
252
|
+
await handleItemUpsert(client, opts.vault, opts.file, opts.idempotencyKey, g.table ?? false);
|
|
253
|
+
}));
|
|
266
254
|
items
|
|
267
255
|
.command('preview')
|
|
268
256
|
.description('Dry-run upsert — shows what would change without writing')
|
|
269
257
|
.requiredOption('--vault <id>')
|
|
270
258
|
.requiredOption('--file <path>', 'path to JSON file containing array of items')
|
|
271
|
-
.action(async (opts,
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
});
|
|
259
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
260
|
+
const client = getClient();
|
|
261
|
+
await handleItemPreview(client, opts.vault, opts.file, g.table ?? false);
|
|
262
|
+
}));
|
|
276
263
|
items
|
|
277
264
|
.command('search')
|
|
278
265
|
.description('Search items in a vault')
|
|
@@ -284,28 +271,25 @@ export function registerItems(program) {
|
|
|
284
271
|
.option('--tag <tagId>')
|
|
285
272
|
.option('--page <n>', '', (v) => parseInt(v, 10))
|
|
286
273
|
.option('--limit <n>', '', (v) => parseInt(v, 10))
|
|
287
|
-
.action(async (opts,
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
});
|
|
274
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
275
|
+
const client = getClient();
|
|
276
|
+
await handleItemSearch(client, opts.vault, { q: opts.q, author: opts.author, year: opts.year, doi: opts.doi, tag: opts.tag, page: opts.page, limit: opts.limit }, g.table ?? false);
|
|
277
|
+
}));
|
|
292
278
|
items
|
|
293
279
|
.command('stats')
|
|
294
280
|
.description('Get vault statistics')
|
|
295
281
|
.requiredOption('--vault <id>')
|
|
296
|
-
.action(async (opts,
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
});
|
|
282
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
283
|
+
const client = getClient();
|
|
284
|
+
await handleItemStats(client, opts.vault, g.table ?? false);
|
|
285
|
+
}));
|
|
301
286
|
items
|
|
302
287
|
.command('changes')
|
|
303
288
|
.description('Get items changed since a timestamp')
|
|
304
289
|
.requiredOption('--vault <id>')
|
|
305
290
|
.requiredOption('--since <ISO>', 'ISO 8601 timestamp')
|
|
306
|
-
.action(async (opts,
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
});
|
|
291
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
292
|
+
const client = getClient();
|
|
293
|
+
await handleItemChanges(client, opts.vault, opts.since, g.table ?? false);
|
|
294
|
+
}));
|
|
311
295
|
}
|
package/dist/commands/pdf.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/commands/pdf.ts
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
|
-
import {
|
|
3
|
+
import { UsageError, action } from '../client.js';
|
|
4
4
|
import { format } from '../format.js';
|
|
5
5
|
export async function handlePdfUpload(client, vaultId, itemId, filePath, tableMode) {
|
|
6
6
|
let pdfBuffer;
|
|
@@ -8,8 +8,7 @@ export async function handlePdfUpload(client, vaultId, itemId, filePath, tableMo
|
|
|
8
8
|
pdfBuffer = readFileSync(filePath);
|
|
9
9
|
}
|
|
10
10
|
catch (e) {
|
|
11
|
-
|
|
12
|
-
process.exit(2);
|
|
11
|
+
throw new UsageError('file_read_error', `Cannot read file: ${String(e)}`);
|
|
13
12
|
}
|
|
14
13
|
const result = await client.uploadItemPdf(vaultId, itemId, pdfBuffer);
|
|
15
14
|
format(result, tableMode);
|
|
@@ -22,9 +21,8 @@ export function registerPdf(program) {
|
|
|
22
21
|
.requiredOption('--vault <id>', 'vault ID')
|
|
23
22
|
.requiredOption('--item <id>', 'vault item ID')
|
|
24
23
|
.requiredOption('--file <path>', 'path to PDF file')
|
|
25
|
-
.action(async (opts,
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
24
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
25
|
+
const client = getClient();
|
|
26
|
+
await handlePdfUpload(client, opts.vault, opts.item, opts.file, g.table ?? false);
|
|
27
|
+
}));
|
|
30
28
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/commands/relations.ts
|
|
2
2
|
import { Option } from 'commander';
|
|
3
|
-
import {
|
|
3
|
+
import { action } from '../client.js';
|
|
4
4
|
import { format } from '../format.js';
|
|
5
5
|
import { registerRelationsScan } from './relationsScan.js';
|
|
6
6
|
import { RELATION_TYPES } from '../types.js';
|
|
@@ -33,11 +33,10 @@ export function registerRelations(program) {
|
|
|
33
33
|
.description('List relations in a vault')
|
|
34
34
|
.requiredOption('--vault <id>')
|
|
35
35
|
.addOption(typeOption())
|
|
36
|
-
.action(async (opts,
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
36
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
37
|
+
const client = getClient();
|
|
38
|
+
await handleRelationsList(client, opts.vault, opts.type, g.table ?? false);
|
|
39
|
+
}));
|
|
41
40
|
relations
|
|
42
41
|
.command('create')
|
|
43
42
|
.description('Create a relation between two publications')
|
|
@@ -45,31 +44,28 @@ export function registerRelations(program) {
|
|
|
45
44
|
.requiredOption('--pub <publicationId>')
|
|
46
45
|
.requiredOption('--related <publicationId>')
|
|
47
46
|
.addOption(typeOption())
|
|
48
|
-
.action(async (opts,
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
47
|
+
.action(action(async ({ opts, g, getClient }) => {
|
|
48
|
+
const client = getClient();
|
|
49
|
+
await handleRelationCreate(client, opts.vault, { pub: opts.pub, related: opts.related, type: opts.type }, g.table ?? false);
|
|
50
|
+
}));
|
|
53
51
|
relations
|
|
54
52
|
.command('update')
|
|
55
53
|
.argument('<relationId>')
|
|
56
54
|
.description('Update a relation type')
|
|
57
55
|
.requiredOption('--vault <id>')
|
|
58
56
|
.addOption(typeOption().makeOptionMandatory())
|
|
59
|
-
.action(async (relationId, opts,
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
57
|
+
.action(action(async ({ args: [relationId], opts, g, getClient }) => {
|
|
58
|
+
const client = getClient();
|
|
59
|
+
await handleRelationUpdate(client, opts.vault, relationId, opts.type, g.table ?? false);
|
|
60
|
+
}));
|
|
64
61
|
relations
|
|
65
62
|
.command('delete')
|
|
66
63
|
.argument('<relationId>')
|
|
67
64
|
.description('Delete a relation')
|
|
68
65
|
.requiredOption('--vault <id>')
|
|
69
|
-
.action(async (relationId, opts,
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
});
|
|
66
|
+
.action(action(async ({ args: [relationId], opts, g, getClient }) => {
|
|
67
|
+
const client = getClient();
|
|
68
|
+
await handleRelationDelete(client, opts.vault, relationId);
|
|
69
|
+
}));
|
|
74
70
|
registerRelationsScan(relations);
|
|
75
71
|
}
|