Extend --print-format with %L

Add format attribute for licenses.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Jelle van der Waa 2022-12-13 14:12:56 +10:00 committed by Allan McRae
parent f5af66f130
commit c1d4a6198c
2 changed files with 12 additions and 2 deletions

View file

@ -239,8 +239,8 @@ Transaction Options (apply to '-S', '-R' and '-U')
builddate, "%d" for description, "%e" for pkgbase, "%f" for filename, builddate, "%d" for description, "%e" for pkgbase, "%f" for filename,
"%g" for base64 encoded PGP signature, "%h" for sha256sum, "%n" for "%g" for base64 encoded PGP signature, "%h" for sha256sum, "%n" for
pkgname, "%p" for packager, "%v" for pkgver, "%l" for location, "%r" pkgname, "%p" for packager, "%v" for pkgver, "%l" for location, "%r"
for repository, "%s" for size, "%C" for checkdepends, "%D" for depends for repository, "%s" for size, "%C" for checkdepends, "%D" for depends,
and "%M" for makedepends. "%L" for licenses, and "%M" for makedepends.
Implies '\--print'. Implies '\--print'.

View file

@ -1279,6 +1279,16 @@ void print_packages(const alpm_list_t *packages)
free(temp); free(temp);
temp = string; temp = string;
} }
/* %L : license */
if(strstr(temp, "%L")) {
alpm_list_t *lst = alpm_pkg_get_licenses(pkg);
char *licenses = concat_list(lst, NULL);
string = strreplace(temp, "%L", licenses);
free(licenses);
free(temp);
temp = string;
}
printf("%s\n", string); printf("%s\n", string);
free(string); free(string);
} }