Skip to content

Commit 7391a7b

Browse files
classabbyampDuncaen
authored andcommitted
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.
1 parent 83e66e2 commit 7391a7b

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

bin/xbps-uhelper/main.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ usage(void)
4646
" Available actions:\n"
4747
" binpkgarch, binpkgver, cmpver, fetch, getpkgdepname,\n"
4848
" getpkgname, getpkgrevision, getpkgversion, pkgmatch, version,\n"
49-
" real-version, arch, getsystemdir\n"
49+
" real-version, arch, getsystemdir, getname, getversion\n"
5050
"\n"
5151
" Action arguments:\n"
5252
" binpkgarch\t<binpkg> ...\n"
@@ -57,6 +57,8 @@ usage(void)
5757
" getpkgname\t\t<string> ...\n"
5858
" getpkgrevision\t<string> ...\n"
5959
" getpkgversion\t<string> ...\n"
60+
" getname\t\t<string> ...\n"
61+
" getversion\t\t<string> ...\n"
6062
" pkgmatch\t\t<pkg-version> <pkg-pattern>\n"
6163
" version\t\t<pkgname> ...\n"
6264
" real-version\t<pkgname> ...\n"
@@ -257,6 +259,41 @@ main(int argc, char **argv)
257259
printf("%s\n", version);
258260
}
259261
}
262+
} else if (strcmp(argv[0], "getname") == 0) {
263+
/* returns the name of a pkg strings or pkg patterns */
264+
if (argc < 2)
265+
usage();
266+
267+
for (i = 1; i < argc; i++) {
268+
if (xbps_pkgpattern_name(pkgname, sizeof(pkgname), argv[i]) ||
269+
xbps_pkg_name(pkgname, sizeof(pkgname), argv[i])) {
270+
printf("%s\n", pkgname);
271+
} else {
272+
xbps_error_printf(
273+
"Invalid string '%s', expected <string><comparator><version> "
274+
"or <string>-<version>_<revision>\n", argv[i]);
275+
rv = 1;
276+
}
277+
}
278+
} else if (strcmp(argv[0], "getversion") == 0) {
279+
/* returns the version of a pkg strings or pkg patterns */
280+
if (argc < 2)
281+
usage();
282+
283+
for (i = 1; i < argc; i++) {
284+
version = xbps_pkgpattern_version(argv[i]);
285+
if (version == NULL) {
286+
version = xbps_pkg_version(argv[i]);
287+
if (version == NULL) {
288+
xbps_error_printf(
289+
"Invalid string '%s', expected <string><comparator><version> "
290+
"or <string>-<version>_<revision>\n", argv[i]);
291+
rv = 1;
292+
continue;
293+
}
294+
}
295+
printf("%s\n", version);
296+
}
260297
} else if (strcmp(argv[0], "binpkgver") == 0) {
261298
/* Returns the pkgver of binpkg strings */
262299
if (argc < 2)

0 commit comments

Comments
 (0)