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>
This commit is contained in:
Jonathan Sköld 2021-09-28 23:09:02 +02:00 committed by morganamilo
parent db1c1b6777
commit bec22fcd41
No known key found for this signature in database
GPG key ID: E48D0A8326DE47C5
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>:: *\--print-format* <format>::
Specify a printf-like format to control the output of the '\--print' Specify a printf-like format to control the output of the '\--print'
operation. The possible attributes are: "%n" for pkgname, "%v" for pkgver, operation. The possible attributes are: "%a" for arch, "%n" for pkgname,
"%l" for location, "%r" for repository, and "%s" for size. Implies '\--print'. "%v" for pkgver, "%l" for location, "%r" for repository, and "%s" for size.
Implies '\--print'.
Upgrade Options (apply to '-S' and '-U')[[UO]] 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; alpm_pkg_t *pkg = i->data;
char *string = strdup(config->print_format); char *string = strdup(config->print_format);
char *temp = string; 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 */ /* %n : pkgname */
if(strstr(temp, "%n")) { if(strstr(temp, "%n")) {
string = strreplace(temp, "%n", alpm_pkg_get_name(pkg)); string = strreplace(temp, "%n", alpm_pkg_get_name(pkg));