From 7391a7b2134aa87fd060c9b1e9cee7b14eab9597 Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Thu, 9 Feb 2023 18:46:39 -0500 Subject: [PATCH] bin/xbps-uhelper: add getname and getversion actions these actions are kind of "meta" actions, combining getpkgdepname and getpkgname (and the respective version actions) so that a list of mixed pkgvers and package patterns can be interpreted. This uses the internal format check of `xbps_pkgpattern_{name,version}()` to allow for a fallback to `xbps_pkg_{name,version}()` for exact versions, then falls back to displaying an error message if that also fails. --- bin/xbps-uhelper/main.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index 7bc467a8..dca009d0 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -46,7 +46,7 @@ usage(void) " Available actions:\n" " binpkgarch, binpkgver, cmpver, fetch, getpkgdepname,\n" " getpkgname, getpkgrevision, getpkgversion, pkgmatch, version,\n" - " real-version, arch, getsystemdir\n" + " real-version, arch, getsystemdir, getname, getversion\n" "\n" " Action arguments:\n" " binpkgarch\t ...\n" @@ -57,6 +57,8 @@ usage(void) " getpkgname\t\t ...\n" " getpkgrevision\t ...\n" " getpkgversion\t ...\n" + " getname\t\t ...\n" + " getversion\t\t ...\n" " pkgmatch\t\t \n" " version\t\t ...\n" " real-version\t ...\n" @@ -257,6 +259,41 @@ main(int argc, char **argv) printf("%s\n", version); } } + } else if (strcmp(argv[0], "getname") == 0) { + /* returns the name of a pkg strings or pkg patterns */ + if (argc < 2) + usage(); + + for (i = 1; i < argc; i++) { + if (xbps_pkgpattern_name(pkgname, sizeof(pkgname), argv[i]) || + xbps_pkg_name(pkgname, sizeof(pkgname), argv[i])) { + printf("%s\n", pkgname); + } else { + xbps_error_printf( + "Invalid string '%s', expected " + "or -_\n", argv[i]); + rv = 1; + } + } + } else if (strcmp(argv[0], "getversion") == 0) { + /* returns the version of a pkg strings or pkg patterns */ + if (argc < 2) + usage(); + + for (i = 1; i < argc; i++) { + version = xbps_pkgpattern_version(argv[i]); + if (version == NULL) { + version = xbps_pkg_version(argv[i]); + if (version == NULL) { + xbps_error_printf( + "Invalid string '%s', expected " + "or -_\n", argv[i]); + rv = 1; + continue; + } + } + printf("%s\n", version); + } } else if (strcmp(argv[0], "binpkgver") == 0) { /* Returns the pkgver of binpkg strings */ if (argc < 2)