Skip to content

Add JSON, others(?) Output #2903

Description

@johnnybubonic

Is your feature request related to a problem? Please describe.

Sometimes when trying to programmatically work with yay output (or pacman output), you want/need certain values paired together (e.g. the install date and package name).

It'd be very useful for these cases if, for example, the output could be in JSON (or YAML, or XML, or TOML, or.. whatever), given that yay and pacman e.g. don't have a DNF/RPM equivalent of result string formatting (e.g. dnf ... --qf, rpm ... --qf).

(Apologies if this was already suggested/requested; I looked fairly hard but didn't find anything similar.)

Describe the solution you'd like

It'd be VERY useful if an --output=[human|json|yaml|xml|toml] switch (default human, which would use the current printing formatting) could be added to the following operations:

  • -Q / --query
  • -S / --sync
    • --search suboperation
    • --groups suboperation
    • --info` suboperation
    • --list suboperation
    • --owns suboperation
  • -F / --files
    • (all suboperations except --machinereadable and -y/-yy / --refresh/--refresh --refresh)
  • -Y / --yay (?)
    • ("yogurt" mode only; though would imply a non-interactive call I'd imagine)
  • -P / --print

Describe alternatives you've considered

  1. Using ALPM bindings, which... is a lot of setup/teardown instead of just something I could pipe to jq(1) or something.
  2. Parsing the straight output, even with -q, means multiple many calls/invocations in bash (see below)

An example bash script for just getting the package name and install date:

#!/bin/bash

for pkg in $(yay -Qqs some_search_str);
do
	pkginfo="$(yay -Qi ${pkg} | grep -E '^\s*(Name|Install Date)\s*:' )"
	pkgnm="$(echo "${pkginfo}" | grep -E '^\s*N' | cut -f2- -d':' | sed -re 's/^\s+//' -e 's/\s+$//')"
	pkginsttm="$(echo "${pkginfo}" | grep -E '^\s*I' | cut -f2- -d':' | sed -re 's/^\s+//' -e 's/\s+$//')"
	echo -e "${pkgnm}\t${pkginsttm}"
done | \
column -s $'\t' -t

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions