Skip to content

Commit 38192e3

Browse files
committed
ndb: add --id queries
how did I not have this already... Signed-off-by: William Casarin <[email protected]>
1 parent 44d1797 commit 38192e3

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

ndb.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static int usage()
1919
printf("commands\n\n");
2020

2121
printf(" stat\n");
22-
printf(" query [--kind 42] [--notekey key] [--search term] [--limit 42] \n");
22+
printf(" query [--kind 42] [--id abcdef...] [--notekey key] [--search term] [--limit 42] \n");
2323
printf(" [-e abcdef...] [--author abcdef... -a bcdef...] [--relay wss://relay.damus.io]\n");
2424
printf(" profile <pubkey> print the raw profile data for a pubkey\n");
2525
printf(" note-relays <note-id> list the relays a given note id has been seen on\n");
@@ -282,6 +282,23 @@ int main(int argc, char *argv[])
282282
ndb_filter_end_field(f);
283283
argv += 2;
284284
argc -= 2;
285+
} else if (!strcmp(argv[0], "-i") || !strcmp(argv[0], "--id")) {
286+
if (current_field != NDB_FILTER_IDS) {
287+
ndb_filter_end_field(f);
288+
ndb_filter_start_field(f, NDB_FILTER_IDS);
289+
current_field = NDB_FILTER_IDS;
290+
}
291+
292+
len = strlen(argv[1]);
293+
if (len != 64 || !hex_decode(argv[1], 64, tmp_id, sizeof(tmp_id))) {
294+
fprintf(stderr, "invalid hex id\n");
295+
res = 42;
296+
goto cleanup;
297+
}
298+
299+
ndb_filter_add_id_element(f, tmp_id);
300+
argv += 2;
301+
argc -= 2;
285302
} else if (!strcmp(argv[0], "-e")) {
286303
if (current_field != 'e') {
287304
if (!ndb_filter_start_tag_field(f, 'e')) {
@@ -307,14 +324,11 @@ int main(int argc, char *argv[])
307324
argv += 2;
308325
argc -= 2;
309326
} else if (!strcmp(argv[0], "-a") || !strcmp(argv[0], "--author")) {
310-
if (current_field) {
311-
ndb_filter_end_field(f);
312-
current_field = 0;
313-
}
314327
if (current_field != NDB_FILTER_AUTHORS) {
328+
ndb_filter_end_field(f);
315329
ndb_filter_start_field(f, NDB_FILTER_AUTHORS);
330+
current_field = NDB_FILTER_AUTHORS;
316331
}
317-
current_field = NDB_FILTER_AUTHORS;
318332

319333
len = strlen(argv[1]);
320334
if (len != 64 || !hex_decode(argv[1], 64, tmp_id, sizeof(tmp_id))) {
@@ -331,6 +345,10 @@ int main(int argc, char *argv[])
331345

332346
argv += 2;
333347
argc -= 2;
348+
} else {
349+
fprintf(stderr, "unrecognized option: %s\n", argv[0]);
350+
res = 100;
351+
goto cleanup;
334352
}
335353
}
336354

0 commit comments

Comments
 (0)