Add tag listing functionality
[blerg.git] / blergtool.c
index a0148c0..d5aef50 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "database.h"
+#include "tags.h"
 
 void help() {
        printf("Usage: blergtool <store|fetch> <storename> [record]\n");
@@ -50,6 +51,19 @@ int main(int argc, char *argv[]) {
                blerg_close(f);
                fwrite(data, 1, size, stdout);
                free(data);
+       } else if (strncmp(argv[1], "list", 4) == 0) {
+               char *tag = argv[2];
+               uint64_t count = 50;
+               struct tag *list = tag_list(tag, 0, &count, -1);
+               if (list == NULL) {
+                       printf("No entries");
+               } else {
+                       int i;
+                       for (i = 0; i < count; i++) {
+                               printf("%s %d\n", list[i].author, list[i].record);
+                       }
+                       free(list);
+               }
        } else {
                help();
        }