# HG changeset patch # User Mike Becker # Date 1377859695 -7200 # Node ID ad0c9dacd7e3cd32ac022c854ebc7352a1552a9c # Parent 1b87b3b1921e6c74d68082d6fef62fe76209efdd errors on too many arguments diff -r 1b87b3b1921e -r ad0c9dacd7e3 dav/main.c --- a/dav/main.c Mon Aug 26 14:44:21 2013 +0200 +++ b/dav/main.c Fri Aug 30 12:48:15 2013 +0200 @@ -196,8 +196,8 @@ int cmd_list(CmdArgs *a) { - if(a->argc == 0) { - fprintf(stderr, "Too few arguments\n"); + if(a->argc != 1) { + fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); return -1; } @@ -427,8 +427,9 @@ } int cmd_get(CmdArgs *a) { - if(a->argc == 0) { - fprintf(stderr, "Too few arguments\n"); + if(a->argc != 1) { + // TODO: change this, when get supports retrieval of multiple files + fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); return -1; } @@ -618,8 +619,9 @@ } int cmd_put(CmdArgs *a) { - if(a->argc < 2) { - fprintf(stderr, "Too few arguments\n"); + if(a->argc != 2) { + // TODO: change, when put supports multiple files (however it should do) + fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many"); return -1; } @@ -771,8 +773,9 @@ int cmd_remove(CmdArgs *a) { - if(a->argc < 1) { - fprintf(stderr, "Too few arguments\n"); + if(a->argc != 1) { + // TODO: change, when removal of multiple files is supported + fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); return -1; } @@ -805,8 +808,9 @@ } int cmd_mkdir(CmdArgs *a) { - if(a->argc < 1) { - fprintf(stderr, "Too few arguments\n"); + if(a->argc != 1) { + // TODO: change, when creation of multiple dirs is supported + fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); return -1; } @@ -861,7 +865,7 @@ putenv("LC_TIME=C"); size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT\n", date); fwrite(str, 1, len, stdout); - } else { + } else if (a->argc == 1) { DavSession *sn = NULL; char *url = a->argv[0]; char *root = NULL; @@ -884,8 +888,11 @@ } else { return -1; } + return 0; + } else { + fprintf(stderr, "Too many arguments\n"); + return -1; } - return 0; } int cmd_sync(CmdArgs *a) {