adds repository-url command

Fri, 15 Jun 2018 15:51:21 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 15 Jun 2018 15:51:21 +0200
changeset 419
0b48f935f8a6
parent 418
cfdeeed64ac5
child 420
ad419882e06e

adds repository-url command

dav/main.c file | annotate | diff | comparison | revisions
dav/main.h file | annotate | diff | comparison | revisions
--- a/dav/main.c	Wed Jun 13 18:14:33 2018 +0200
+++ b/dav/main.c	Fri Jun 15 15:51:21 2018 +0200
@@ -149,6 +149,9 @@
         } else if(!strcasecmp(cmd, "list-repositories")
                 || !strcasecmp(cmd, "list-repos")) {
             ret = list_repositories();
+        } else if(!strcasecmp(cmd, "repository-url")
+                || !strcasecmp(cmd, "repo-url")) {
+            ret = cmd_repository_url(args);
         } else if(!strcasecmp(cmd, "version") || !strcasecmp(cmd, "-version")
                 || !strcasecmp(cmd, "--version")) {
             fprintf(stderr, "dav %s\n", DAV_VERSION);
@@ -247,6 +250,7 @@
     fprintf(stderr, "        add-repository\n");
     fprintf(stderr, "        remove-repository\n");
     fprintf(stderr, "        list-repositories\n");
+    fprintf(stderr, "        repository-url\n");
     fprintf(stderr, "        check-config\n");
     fprintf(stderr, "\n");
     fprintf(stderr,
@@ -1956,3 +1960,25 @@
     
     return -1;
 }
+
+int cmd_repository_url(CmdArgs *args) {
+    if(args->argc != 1) {
+        fprintf(stderr, "Too few arguments\n");
+        fprintf(stderr, "Usage: dav repository-url <name>\n");
+        return -1;
+    }
+    
+    sstr_t reponame = sstr(args->argv[0]);
+    Repository* repo = get_repository(reponame);
+    if(repo) {
+        sstr_t url = sstr(repo->url);
+        if(url.ptr[url.length-1] == '/') {
+            printf("%s\n", repo->url);
+        } else {
+            printf("%s/\n", repo->url);
+        }
+    } else {
+        fprintf(stderr, "Repository %s does not exist.\n", reponame.ptr);
+        return -1;
+    }
+}
--- a/dav/main.h	Wed Jun 13 18:14:33 2018 +0200
+++ b/dav/main.h	Fri Jun 15 15:51:21 2018 +0200
@@ -102,6 +102,8 @@
 int cmd_add_repository(CmdArgs *args);
 int cmd_remove_repository(CmdArgs *args);
 
+int cmd_repository_url(CmdArgs *args);
+
 #ifdef	__cplusplus
 }
 #endif

mercurial