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 )
@@ -46,6 +48,7 @@ usage(bool fail)
46
48
" -F, --format <format> Format for list output\n"
47
49
" -h, --help Show usage\n"
48
50
" -i, --ignore-conf-repos Ignore repositories defined in xbps.d\n"
51
+ " -J, --json Print output as json\n"
49
52
" -M, --memory-sync Remote repository data is fetched and stored\n"
50
53
" in memory, ignoring on-disk repodata archives\n"
51
54
" -p, --property PROP[,...] Show properties for PKGNAME\n"
@@ -100,13 +103,14 @@ filter_repolock(xbps_object_t obj)
100
103
int
101
104
main (int argc , char * * argv )
102
105
{
103
- const char * shortopts = "C:c:dF:f:hHiLlMmOo :p:Rr:s:S:VvX:x:" ;
106
+ const char * shortopts = "C:c:dF:f:hHiJLlMmOo :p:Rr:s:S:VvX:x:" ;
104
107
const struct option longopts [] = {
105
108
{ "config" , required_argument , NULL , 'C' },
106
109
{ "cachedir" , required_argument , NULL , 'c' },
107
110
{ "debug" , no_argument , NULL , 'd' },
108
111
{ "help" , no_argument , NULL , 'h' },
109
112
{ "ignore-conf-repos" , no_argument , NULL , 'i' },
113
+ { "json" , no_argument , NULL , 'J' },
110
114
{ "list-repos" , no_argument , NULL , 'L' },
111
115
{ "list-pkgs" , no_argument , NULL , 'l' },
112
116
{ "list-hold-pkgs" , no_argument , NULL , 'H' },
@@ -137,6 +141,7 @@ main(int argc, char **argv)
137
141
bool list_pkgs , list_repos , orphans , own , list_repolock ;
138
142
bool list_manual , list_hold , show_prop , show_files , show_deps , show_rdeps ;
139
143
bool show , pkg_search , regex , repo_mode , opmode , fulldeptree ;
144
+ int json = 0 ;
140
145
141
146
rootdir = cachedir = confdir = props = pkg = catfile = format = NULL ;
142
147
flags = rv = c = 0 ;
@@ -165,6 +170,9 @@ main(int argc, char **argv)
165
170
case 'F' :
166
171
format = optarg ;
167
172
break ;
173
+ case 'J' :
174
+ json ++ ;
175
+ break ;
168
176
case 'H' :
169
177
list_hold = opmode = true;
170
178
break ;
@@ -286,20 +294,21 @@ main(int argc, char **argv)
286
294
rv = repo_list (& xh );
287
295
288
296
} else if (list_hold ) {
289
- rv = list_pkgdb (& xh , filter_hold , format ? format : "{pkgver}\n" ) < 0 ;
297
+ rv = list_pkgdb (& xh , filter_hold , format ? format : "{pkgver}\n" , json ) < 0 ;
290
298
291
299
} else if (list_repolock ) {
292
- rv = list_pkgdb (& xh , filter_repolock , format ? format : "{pkgver}\n" ) < 0 ;
300
+ rv = list_pkgdb (& xh , filter_repolock , format ? format : "{pkgver}\n" , json ) < 0 ;
293
301
294
302
} else if (list_manual ) {
295
- rv = list_pkgdb (& xh , filter_manual , format ? format : "{pkgver}\n" ) < 0 ;
303
+ rv = list_pkgdb (& xh , filter_manual , format ? format : "{pkgver}\n" , json ) < 0 ;
296
304
297
305
} else if (list_pkgs ) {
298
306
/* list available pkgs */
299
- if (format )
300
- rv = list_pkgdb (& xh , NULL , format );
301
- else
307
+ if (format || json > 0 ) {
308
+ rv = list_pkgdb (& xh , NULL , format , json );
309
+ } else {
302
310
rv = list_pkgs_pkgdb (& xh );
311
+ }
303
312
304
313
} else if (orphans ) {
305
314
/* list pkg orphans */
0 commit comments