void-linux / xbps

The X Binary Package System (XBPS)
https://voidlinux.org/xbps/
Other
822 stars 124 forks source link

`xbps-query`: Unify default output formats of package lists #459

Open camoz opened 2 years ago

camoz commented 2 years ago

Right now, xbps-query has different default output formats (or even only one output format) for some commands.

Multiple columns:

[root@rootfs /]# xbps-query -l
ii acl-2.3.1_1                     Access Control List filesystem support
ii acpid-2.0.33_2                  ACPI Daemon (acpid) With Netlink Support
...
[root@rootfs /]# xbps-query -s ab
[*] bash-completion-2.11_2         Programmable completion for the GNU Bash shell
[*] bzip2-1.0.8_1                  Freely available, patent free, high-quality data compressor
...

Single column:

[root@rootfs /]# xbps-query -m  # same for -O and -X
acpid-2.0.33_2
base-voidstrap-0.11_1
...
[root@rootfs /]# xbps-query -x sway
swaybg>=0
xorg-server-xwayland>=0
...

I think it would be nice if the first two examples (-l and -s) had the same output format. Maybe we can introduce a new "package state descriptor" like nn or -- for "currently not installed" packages? Right now we have, according to xbps-query(1):

         ii Package is installed.
         uu Package is unpacked but must be configured with xbps-reconfigure(1).
         hr Package is half-removed, and can be fully removed with xbps-remove(1).
         ?? Package state is unknown.

Overall, I think it would be useful to have two different easily reachable output formats (by easily reachable I mean e.g. a simple flag, not a complete --format=... specifier). Often, e.g. when searching packages via -s, additional information like the short description and package version is useful. But often it is also useful to just have a list of package names (without any version string etc.) for batch processing, e.g. saving a list of all manually installed packages to be later fed into xbps-install on another system. I think these are two common scenarios, and having only two default output formats for the various package listing options of xbps-query will make it easier (because more predictable) to use. The flags could be named -v|--verbose (already exists, but maybe it could be used for this) and -q|--quiet. Some modes, like -s, are verbose by default and can be made shorter using -q. And some modes, like -m, are short by default and can be made more verbose using -v.

There was also the (IMO great) idea of adding a --format=... option, however I'm talking about the default output format and perhaps an easily reachable secondary one, for the most common cases.

Related issues/PRs:

Chocimier commented 2 years ago

Similarly, xbps-install has at least four output formats.

The problem with changing defaults is that it will break lots of tools parsing xbps output. Is there any gain besides consistency of not quite the same data?

terminal

$ xbps-install --repository=https://alpha.de.repo.voidlinux.org/current nawk -r /tmp/ -S
Name  Action    Version           New version            Download size
glibc install   -                 2.32_2                 8586KB 
nawk  install   -                 20210110_1             67KB 

Size to download:             8655KB
Size required on disk:          33MB
Space available on disk:        16GB

pipe

$ xbps-install --repository=https://alpha.de.repo.voidlinux.org/current nawk -r /tmp/ -S | cat
2 packages will be downloaded:

  glibc-2.32_2 
  nawk-20210110_1 
2 packages will be installed:

  glibc-2.32_2 
  nawk-20210110_1 

Size to download:             8655KB
Size required on disk:          33MB
Space available on disk:        16GB

narrow terminal

$ xbps-install --repository=https://alpha.de.repo.voidlinux.org/current nawk -r /tmp/ -S
2 packages will be downloaded:
  glibc-2.32_2 nawk-20210110_1 
2 packages will be installed:
  glibc-2.32_2 nawk-20210110_1 

Size to download:             8655KB
Size required on disk:          33MB
Space available on disk:        16GB

with --dry-run

$ xbps-install --repository=https://alpha.de.repo.voidlinux.org/current nawk -r /tmp/ -S -n
glibc-2.32_2 install x86_64 https://alpha.de.repo.voidlinux.org/current 34384831 8792402
nawk-20210110_1 install x86_64 https://alpha.de.repo.voidlinux.org/current 156769 68850
camoz commented 2 years ago

Similarly, xbps-install has at least four output formats.

Thanks for the illustrations, I didn't know that!

The problem with changing defaults is that it will break lots of tools parsing xbps output.

Yes. I'm not really used to developing/deploying such big software projects with many users, so I may be not paying enough attention to that. But sometimes I think you have to make some changes, even if they break something, to move forward. But the gains of what I proposed here are probably not high enough to justify that.

Is there any gain besides consistency of not quite the same data?

What comes to my mind: