adds list-tags command to dav-sync

Sun, 27 May 2018 12:57:12 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 27 May 2018 12:57:12 +0200
changeset 377
d6d7c16dd066
parent 376
222997d48ae1
child 378
d64ecd8d6969

adds list-tags command to dav-sync

dav/sync.c file | annotate | diff | comparison | revisions
dav/sync.h file | annotate | diff | comparison | revisions
dav/version.h file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Sun May 27 11:47:49 2018 +0200
+++ b/dav/sync.c	Sun May 27 12:57:12 2018 +0200
@@ -134,6 +134,8 @@
             ret = cmd_remove_tag(args);
         } else if(!strcmp(cmd, "update-tags")) {
             ret = cmd_update_tags(args);
+        } else if(!strcmp(cmd, "list-tags")) {
+            ret = cmd_list_tags(args);
         } else if(!strcmp(cmd, "add-dir")
                 || !strcmp(cmd, "add-directory")) {
             ret = cmd_add_directory(args);
@@ -174,7 +176,8 @@
     fprintf(stderr, "        empty-trash <directory>\n");
     fprintf(stderr, "        add-tag [-s <syncdir>] <file> <tag>\n");
     fprintf(stderr, "        remove-tag [-s <syncdir>] <file> <tag>\n");
-    fprintf(stderr, "        update-tags [-s <syncdir>] <file> [tags]\n\n");
+    fprintf(stderr, "        update-tags [-s <syncdir>] <file> [tags]\n");
+    fprintf(stderr, "        update-tags [-s <syncdir>] <file>\n\n");
     
     fprintf(stderr, "Options:\n");
     fprintf(stderr, "        -c         Disable conflict detection\n");
@@ -1443,7 +1446,7 @@
                 ret = -1;
             }
         } else {
-            // TODO: relete xattr
+            // TODO: delete xattr
             //ret = xattr_remove(path, dir->tagconfig->xattr_name);
         }
     }
@@ -2073,6 +2076,7 @@
 #define CMD_TAG_ADD    0
 #define CMD_TAG_REMOVE 1
 #define CMD_TAG_UPDATE 2
+#define CMD_TAG_LIST   3
 int cmd_add_tag(CmdArgs *args) {
     if(args->argc != 2) {
         fprintf(stderr, "Too %s arguments\n", args->argc <= 1 ? "few" : "many");
@@ -2097,6 +2101,14 @@
     return cmd_tagopt(args, CMD_TAG_UPDATE);
 }
 
+int cmd_list_tags(CmdArgs *args) {
+    if(args->argc != 1) {
+        fprintf(stderr, "Too %s arguments\n", args->argc <= 1 ? "few" : "many");
+        return -1;
+    }
+    return cmd_tagopt(args, CMD_TAG_LIST);
+}
+
 int cmd_tagopt(CmdArgs *args, int cmd) {
     SyncFile file;
     int ret = 0;
@@ -2123,7 +2135,7 @@
     UcxList *tags = NULL;
     DavBool store_tags = FALSE;
     
-    if(cmd == CMD_TAG_ADD || cmd == CMD_TAG_REMOVE) {
+    if(cmd != CMD_TAG_UPDATE) {
         char *tag = args->argv[1];
         char *tagcolor = NULL; // TODO: get color
 
@@ -2131,7 +2143,9 @@
         UcxList *x = NULL;
         UCX_FOREACH(elm, tags) {
             DavTag *t = elm->data;
-            if(!strcmp(t->name, tag)) {
+            if(cmd == CMD_TAG_LIST) {
+                printf("%s\n", t->name);
+            } else if(!strcmp(t->name, tag)) {
                 x = elm;
                 break;
             }
@@ -2145,7 +2159,7 @@
                 tags = ucx_list_append(tags, newtag);
                 store_tags = TRUE;
             }
-        } else {
+        } else if(cmd == CMD_TAG_REMOVE) {
             if(tags) {
                 tags = ucx_list_remove(tags, x);
             }
--- a/dav/sync.h	Sun May 27 11:47:49 2018 +0200
+++ b/dav/sync.h	Sun May 27 12:57:12 2018 +0200
@@ -113,6 +113,7 @@
 int cmd_add_tag(CmdArgs *args);
 int cmd_remove_tag(CmdArgs *args);
 int cmd_update_tags(CmdArgs *args);
+int cmd_list_tags(CmdArgs *args);
 int cmd_tagopt(CmdArgs *args, int cmd);
 
 /*
--- a/dav/version.h	Sun May 27 11:47:49 2018 +0200
+++ b/dav/version.h	Sun May 27 12:57:12 2018 +0200
@@ -27,6 +27,6 @@
  */
 
 #ifndef DAV_VERSION
-#define DAV_VERSION "1.1 dev"
+#define DAV_VERSION "1.2 RC1"
 #endif
 

mercurial