|
33 | 33 | #include <xbps.h> |
34 | 34 |
|
35 | 35 | #include "defs.h" |
| 36 | +#include "xbps.h" |
| 37 | +#include "xbps/json.h" |
36 | 38 |
|
37 | 39 | static void __attribute__((noreturn)) |
38 | 40 | usage(bool fail) |
@@ -100,7 +102,7 @@ filter_repolock(xbps_object_t obj) |
100 | 102 | int |
101 | 103 | main(int argc, char **argv) |
102 | 104 | { |
103 | | - const char *shortopts = "C:c:dF:f:hHiLlMmOo:p:Rr:s:S:VvX:x:"; |
| 105 | + const char *shortopts = "C:c:dF:f:hHiJLlMmOo:p:Rr:s:S:VvX:x:"; |
104 | 106 | const struct option longopts[] = { |
105 | 107 | { "config", required_argument, NULL, 'C' }, |
106 | 108 | { "cachedir", required_argument, NULL, 'c' }, |
@@ -137,6 +139,7 @@ main(int argc, char **argv) |
137 | 139 | bool list_pkgs, list_repos, orphans, own, list_repolock; |
138 | 140 | bool list_manual, list_hold, show_prop, show_files, show_deps, show_rdeps; |
139 | 141 | bool show, pkg_search, regex, repo_mode, opmode, fulldeptree; |
| 142 | + int json = 0; |
140 | 143 |
|
141 | 144 | rootdir = cachedir = confdir = props = pkg = catfile = format = NULL; |
142 | 145 | flags = rv = c = 0; |
@@ -165,6 +168,9 @@ main(int argc, char **argv) |
165 | 168 | case 'F': |
166 | 169 | format = optarg; |
167 | 170 | break; |
| 171 | + case 'J': |
| 172 | + json++; |
| 173 | + break; |
168 | 174 | case 'H': |
169 | 175 | list_hold = opmode = true; |
170 | 176 | break; |
@@ -286,20 +292,21 @@ main(int argc, char **argv) |
286 | 292 | rv = repo_list(&xh); |
287 | 293 |
|
288 | 294 | } else if (list_hold) { |
289 | | - rv = list_pkgdb(&xh, filter_hold, format ? format : "{pkgver}\n") < 0; |
| 295 | + rv = list_pkgdb(&xh, filter_hold, format ? format : "{pkgver}\n", json) < 0; |
290 | 296 |
|
291 | 297 | } else if (list_repolock) { |
292 | | - rv = list_pkgdb(&xh, filter_repolock, format ? format : "{pkgver}\n") < 0; |
| 298 | + rv = list_pkgdb(&xh, filter_repolock, format ? format : "{pkgver}\n", json) < 0; |
293 | 299 |
|
294 | 300 | } else if (list_manual) { |
295 | | - rv = list_pkgdb(&xh, filter_manual, format ? format : "{pkgver}\n") < 0; |
| 301 | + rv = list_pkgdb(&xh, filter_manual, format ? format : "{pkgver}\n", json) < 0; |
296 | 302 |
|
297 | 303 | } else if (list_pkgs) { |
298 | 304 | /* list available pkgs */ |
299 | | - if (format) |
300 | | - rv = list_pkgdb(&xh, NULL, format); |
301 | | - else |
| 305 | + if (format || json > 0) { |
| 306 | + rv = list_pkgdb(&xh, NULL, format, json); |
| 307 | + } else { |
302 | 308 | rv = list_pkgs_pkgdb(&xh); |
| 309 | + } |
303 | 310 |
|
304 | 311 | } else if (orphans) { |
305 | 312 | /* list pkg orphans */ |
|
0 commit comments