Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
05cfc88
lib/compat/humanize_number.c: switch to freebsd version
Duncaen Feb 21, 2023
bac5de5
lib: add xbps_fmt* functions for string formatting
Duncaen Feb 20, 2023
5d4f0f2
bin/xbps-query: add -F/--format flag
Duncaen Feb 20, 2023
a6a529c
tests: add tests for xbps_fmt* functions
Duncaen Feb 21, 2023
6d228ac
lib/format.c: new humanize format !humanize[ ][.][width][minscale[max…
Duncaen Feb 21, 2023
e95718b
bin/xbps-query: document format flag
Duncaen Feb 21, 2023
16422b5
lib/format.c: split/cleanup code
Duncaen Mar 10, 2023
fd5157f
lib/format.c: change escaped [{}] to \\[{}]
Duncaen Mar 10, 2023
2162279
lib/format.c: add some more escape sequences
Duncaen Mar 10, 2023
90ce850
bin/xbps-query: update/clean format documentation
Duncaen Mar 10, 2023
f374d6c
bin/xbps-query: fix humanize "i" SI prefixs documentation
Duncaen Mar 10, 2023
578ce80
lib/format.c: refactor a bit
Duncaen Mar 14, 2023
a9c2747
lib/format.c: add optional default to format string variables
Duncaen Mar 14, 2023
c02cdc6
lib/format.c: simplify escape characters
Duncaen Mar 14, 2023
5c31fcb
lib/format.c: fix parsing empty default string
Duncaen Mar 14, 2023
cc8d7d2
lib/format.c: fix xbps_fmts*
Duncaen Mar 14, 2023
6baa761
lib/format.c: handle errors from nexttok
Duncaen Jun 19, 2023
1b78587
lib/json.c: add json printing stuff
Duncaen Sep 18, 2023
354fb92
lib/format.c: add json value conversion
Duncaen Sep 18, 2023
40d4427
bin/xbps-query: add --json flag as alternative to --format
Duncaen Sep 18, 2023
69aa731
lib/format: add \e escape, fix typos in format spec, remove dbg print
classabbyamp Mar 15, 2023
8715af4
bin/xbps-query: make --json compact if there is no indention
Duncaen Sep 18, 2023
c12f5aa
bin/xbps-query: cleanup mode handling
Duncaen Sep 19, 2023
03e1b5d
bin/xbps-query: move --list-repo to main.c, list.c is exclusively pac…
Duncaen Sep 19, 2023
8049a17
bin/xbps-query: add format string support to --list-repos
Duncaen Sep 19, 2023
ae7ccd1
bin/xbps-query: document the --json flag better
Duncaen Sep 19, 2023
31cec81
lib/format.c: IWYU
Duncaen Sep 19, 2023
7d038ca
include: split xbps_fmt stuff into its own header
Duncaen Sep 19, 2023
dcc60f4
lib/format.c: make struct xbps_fmt private
Duncaen Sep 19, 2023
17182be
bin/xbps-query: add pkgname,version and revision format variables
Duncaen Sep 19, 2023
aecab4c
lib/json.c: names and documentation
Duncaen Sep 19, 2023
ae11e15
bin/xbps-query: bring back default/null values for package formats
Duncaen Sep 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/xbps-query/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int ownedby(struct xbps_handle *, const char *, bool, bool);
int list_manual_pkgs(struct xbps_handle *, xbps_object_t, const char *, void *, bool *);
int list_orphans(struct xbps_handle *, const char *);
int list_pkgs_pkgdb(struct xbps_handle *);
int list_pkgdb(struct xbps_handle *, int (*filter)(xbps_object_t), const char *format);
int list_pkgdb(struct xbps_handle *, int (*filter)(xbps_object_t), const char *format, int json);

int repo_list(struct xbps_handle *);

Expand Down
35 changes: 24 additions & 11 deletions bin/xbps-query/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "defs.h"
#include "xbps.h"
#include "xbps/json.h"

struct length_max_cb {
const char *key;
Expand Down Expand Up @@ -135,6 +136,7 @@ list_pkgs_pkgdb(struct xbps_handle *xhp)

struct list_pkgdb_cb {
struct xbps_fmt *fmt;
struct xbps_json_printer *json;
int (*filter)(xbps_object_t obj);
};

Expand All @@ -153,23 +155,34 @@ list_pkgdb_cb(struct xbps_handle *xhp UNUSED, xbps_object_t obj,
return 0;
}

r = xbps_fmt_dictionary(ctx->fmt, obj, stdout);
if (r < 0)
return r;
return 0;
if (ctx->fmt) {
r = xbps_fmt_dictionary(ctx->fmt, obj, stdout);
} else if (ctx->json) {
r = xbps_json_print_xbps_object(ctx->json, obj);
fprintf(ctx->json->file, "\n");
} else {
r = -ENOTSUP;
}
return r;
}

int
list_pkgdb(struct xbps_handle *xhp, int (*filter)(xbps_object_t), const char *format)
list_pkgdb(struct xbps_handle *xhp, int (*filter)(xbps_object_t), const char *format, int json)
{
struct list_pkgdb_cb ctx = {.filter = filter};
struct xbps_json_printer pr = {0};
int r;

ctx.fmt = xbps_fmt_parse(format);
if (!ctx.fmt) {
r = -errno;
xbps_error_printf("failed to parse format: %s\n", strerror(-r));
return r;
if (json > 0) {
pr.indent = (json-1) * 2;
pr.file = stdout;
ctx.json = &pr;
} else if (format) {
ctx.fmt = xbps_fmt_parse(format);
if (!ctx.fmt) {
r = -errno;
xbps_error_printf("failed to parse format: %s\n", strerror(-r));
return r;
}
}
r = xbps_pkgdb_foreach_cb(xhp, list_pkgdb_cb, &ctx);
xbps_fmt_free(ctx.fmt);
Expand Down
23 changes: 16 additions & 7 deletions bin/xbps-query/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <xbps.h>

#include "defs.h"
#include "xbps.h"
#include "xbps/json.h"

static void __attribute__((noreturn))
usage(bool fail)
Expand All @@ -46,6 +48,7 @@ usage(bool fail)
" -F, --format <format> Format for list output\n"
" -h, --help Show usage\n"
" -i, --ignore-conf-repos Ignore repositories defined in xbps.d\n"
" -J, --json Print output as json\n"
" -M, --memory-sync Remote repository data is fetched and stored\n"
" in memory, ignoring on-disk repodata archives\n"
" -p, --property PROP[,...] Show properties for PKGNAME\n"
Expand Down Expand Up @@ -100,13 +103,14 @@ filter_repolock(xbps_object_t obj)
int
main(int argc, char **argv)
{
const char *shortopts = "C:c:dF:f:hHiLlMmOo:p:Rr:s:S:VvX:x:";
const char *shortopts = "C:c:dF:f:hHiJLlMmOo:p:Rr:s:S:VvX:x:";
const struct option longopts[] = {
{ "config", required_argument, NULL, 'C' },
{ "cachedir", required_argument, NULL, 'c' },
{ "debug", no_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' },
{ "ignore-conf-repos", no_argument, NULL, 'i' },
{ "json", no_argument, NULL, 'J' },
{ "list-repos", no_argument, NULL, 'L' },
{ "list-pkgs", no_argument, NULL, 'l' },
{ "list-hold-pkgs", no_argument, NULL, 'H' },
Expand Down Expand Up @@ -137,6 +141,7 @@ main(int argc, char **argv)
bool list_pkgs, list_repos, orphans, own, list_repolock;
bool list_manual, list_hold, show_prop, show_files, show_deps, show_rdeps;
bool show, pkg_search, regex, repo_mode, opmode, fulldeptree;
int json = 0;

rootdir = cachedir = confdir = props = pkg = catfile = format = NULL;
flags = rv = c = 0;
Expand Down Expand Up @@ -165,6 +170,9 @@ main(int argc, char **argv)
case 'F':
format = optarg;
break;
case 'J':
json++;
break;
case 'H':
list_hold = opmode = true;
break;
Expand Down Expand Up @@ -286,20 +294,21 @@ main(int argc, char **argv)
rv = repo_list(&xh);

} else if (list_hold) {
rv = list_pkgdb(&xh, filter_hold, format ? format : "{pkgver}\n") < 0;
rv = list_pkgdb(&xh, filter_hold, format ? format : "{pkgver}\n", json) < 0;

} else if (list_repolock) {
rv = list_pkgdb(&xh, filter_repolock, format ? format : "{pkgver}\n") < 0;
rv = list_pkgdb(&xh, filter_repolock, format ? format : "{pkgver}\n", json) < 0;

} else if (list_manual) {
rv = list_pkgdb(&xh, filter_manual, format ? format : "{pkgver}\n") < 0;
rv = list_pkgdb(&xh, filter_manual, format ? format : "{pkgver}\n", json) < 0;

} else if (list_pkgs) {
/* list available pkgs */
if (format)
rv = list_pkgdb(&xh, NULL, format);
else
if (format || json > 0) {
rv = list_pkgdb(&xh, NULL, format, json);
} else {
rv = list_pkgs_pkgdb(&xh);
}

} else if (orphans) {
/* list pkg orphans */
Expand Down
2 changes: 2 additions & 0 deletions bin/xbps-query/xbps-query.1
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ Ignore repositories defined in configuration files.
Only repositories specified in the command line via
.Ar --repository
will be used.
.It Fl J, Fl -json
Print output as json.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to indicate which operating modes --json and --format work in (or get it working in all operating modes)

looks like currently it works for:

-J -F
-l x x
-L
-H x x
--list-repolock-pkgs x x
-m x x
-o
-S
-s
-f 1 1
-x
-X

Footnotes

  1. no but I think track file mode and ownership in files.plist #541 will cover it 2

.It Fl M, Fl -memory-sync
For remote repositories, the data is fetched and stored in memory for the current
operation.
Expand Down