@@ -80,6 +80,20 @@ usage(bool fail)
8080 exit (fail ? EXIT_FAILURE : EXIT_SUCCESS );
8181}
8282
83+ static int
84+ repo_fmt (FILE * fp , const struct xbps_fmt * fmt , void * data )
85+ {
86+ struct xbps_repo * repo = data ;
87+ if (strcmp (fmt -> var , "url" ) == 0 ) {
88+ return xbps_fmt_print_string (fmt , repo -> uri , 0 , fp );
89+ } else if (strcmp (fmt -> var , "signed" ) == 0 ) {
90+ return xbps_fmt_print_string (fmt , repo -> is_signed ? "true" : "false" , 0 , fp );
91+ } else if (strcmp (fmt -> var , "packages" ) == 0 ) {
92+ return xbps_fmt_print_number (fmt , xbps_dictionary_count (repo -> idx ), fp );
93+ }
94+ return 0 ;
95+ }
96+
8397static void
8498show_repo (struct xbps_repo * repo )
8599{
@@ -108,8 +122,16 @@ show_repo(struct xbps_repo *repo)
108122}
109123
110124static int
111- show_repos (struct xbps_handle * xhp )
125+ show_repos (struct xbps_handle * xhp , const char * format )
112126{
127+ struct xbps_fmt * fmt = NULL ;
128+ if (format ) {
129+ fmt = xbps_fmt_parse (format );
130+ if (!fmt ) {
131+ xbps_error_printf ("failed to parse format: %s\n" , strerror (errno ));
132+ return 1 ;
133+ }
134+ }
113135 for (unsigned int i = 0 ; i < xbps_array_count (xhp -> repositories ); i ++ ) {
114136 const char * repouri = NULL ;
115137 struct xbps_repo * repo ;
@@ -119,9 +141,18 @@ show_repos(struct xbps_handle *xhp)
119141 printf ("%5zd %s (RSA maybe-signed)\n" , (ssize_t )-1 , repouri );
120142 continue ;
121143 }
122- show_repo (repo );
144+ if (fmt ) {
145+ int r = xbps_fmt (fmt , repo_fmt , repo , stdout );
146+ if (r < 0 ) {
147+ xbps_error_printf ("failed to format repo: %s\n" , strerror (- r ));
148+ return 1 ;
149+ }
150+ } else {
151+ show_repo (repo );
152+ }
123153 xbps_repo_release (repo );
124154 }
155+ xbps_fmt_free (fmt );
125156 return 0 ;
126157}
127158
@@ -354,7 +385,7 @@ main(int argc, char **argv)
354385 rv = list_pkgdb (& xh , filter_repolock , format ? format : "{pkgver}\n" , json ) < 0 ;
355386 break ;
356387 case SHOW_REPOS :
357- rv = show_repos (& xh );
388+ rv = show_repos (& xh , format );
358389 break ;
359390 case SEARCH_FILE :
360391 rv = ownedby (& xh , pkg , repo_mode , regex );
0 commit comments