util.c: add "%O" to --print-format

Add the option to print optional depends with "%O".

Signed-off-by: Jelle van der Waa <jelle@archlinux.org>
This commit is contained in:
Jelle van der Waa 2022-09-16 11:15:30 +02:00 committed by Allan McRae
parent 5bd0b98b42
commit 909f2e86c3
2 changed files with 11 additions and 2 deletions

View file

@ -240,8 +240,8 @@ Transaction Options (apply to '-S', '-R' and '-U')
"%g" for base64 encoded PGP signature, "%h" for sha256sum, "%n" for
pkgname, "%p" for packager, "%v" for pkgver, "%l" for location, "%r"
for repository, "%s" for size, "%C" for checkdepends, "%D" for depends,
"%L" for licenses, and "%M" for makedepends, "%P" for provides and
"%R" for replaces.
"%L" for licenses, and "%M" for makedepends, "%O" for optional depends,
"%P" for provides and "%R" for replaces.
Implies '\--print'.

View file

@ -1279,6 +1279,15 @@ void print_packages(const alpm_list_t *packages)
free(temp);
temp = string;
}
/* %O : optional */
if(strstr(temp, "%O")) {
alpm_list_t *lst = alpm_pkg_get_optdepends(pkg);
char *depends = concat_list(lst, (formatfn)alpm_dep_compute_string);
string = strreplace(temp, "%O", depends);
free(depends);
free(temp);
temp = string;
}
/* %P : provides */
if(strstr(temp, "%P")) {
alpm_list_t *lst = alpm_pkg_get_provides(pkg);