Print the target arch when using the %a format specifier

Adds the %a format specifier to allow printing of a target's arch
when using --print-format.

Signed-off-by: Jonathan Sköld <arch@skold.dev>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Jonathan Sköld 2021-09-28 23:09:02 +02:00 committed by Allan McRae
parent 446972b404
commit a8d9fb8d9c
2 changed files with 13 additions and 2 deletions

View file

@ -235,8 +235,9 @@ Transaction Options (apply to '-S', '-R' and '-U')
*\--print-format* <format>::
Specify a printf-like format to control the output of the '\--print'
operation. The possible attributes are: "%n" for pkgname, "%v" for pkgver,
"%l" for location, "%r" for repository, and "%s" for size. Implies '\--print'.
operation. The possible attributes are: "%a" for arch, "%n" for pkgname,
"%v" for pkgver, "%l" for location, "%r" for repository, and "%s" for size.
Implies '\--print'.
Upgrade Options (apply to '-S' and '-U')[[UO]]

View file

@ -1146,6 +1146,16 @@ void print_packages(const alpm_list_t *packages)
alpm_pkg_t *pkg = i->data;
char *string = strdup(config->print_format);
char *temp = string;
/* %a : arch */
if(strstr(temp, "%a")) {
const char *arch = alpm_pkg_get_arch(pkg);
if(arch == NULL) {
arch = "";
}
string = strreplace(temp, "%a", arch);
free(temp);
temp = string;
}
/* %n : pkgname */
if(strstr(temp, "%n")) {
string = strreplace(temp, "%n", alpm_pkg_get_name(pkg));