--list now honours --format

This commit is contained in:
Jan-Piet Mens
2015-08-23 11:19:25 +02:00
parent 91f0a91fc5
commit fc2c618ea4
2 changed files with 14 additions and 4 deletions

17
ocat.c
View File

@@ -186,10 +186,21 @@ int main(int argc, char **argv)
fprintf(stderr, "%s: cannot list\n", progname);
exit(2);
}
js = json_stringify(json, " ");
printf("%s\n", js);
if (otype == JSON) {
js = json_stringify(json, " ");
printf("%s\n", js);
free(js);
} else {
JsonNode *f, *arr;
if ((arr = json_find_member(json, "results")) != NULL) { // get array
json_foreach(f, arr) {
printf("%s\n", f->string_);
}
}
}
json_delete(json);
free(js);
return (0);
}

View File

@@ -119,7 +119,6 @@ static void ls(char *path, JsonNode *obj)
struct dirent *dp;
JsonNode *jarr = json_mkarray();
printf("opendir %s\n", path);
if ((dirp = opendir(path)) == NULL) {
json_append_member(obj, "error", json_mkstring("Cannot open requested directory"));
return;