From: Morgan Aldridge Subject: Re: pkg_add -IQ does not show single-line comment for packages matching query To: tech@openbsd.org Cc: Marc.Espie.OpenBSD@gmail.com Date: Tue, 30 Apr 2024 21:53:31 -0400 On Sun, Nov 12, 2023 at 9:15 AM Morgan Aldridge wrote: > > On Sat, Nov 11, 2023 at 9:05 PM Morgan Aldridge > wrote: > > > > On Fri, Nov 10, 2023 at 8:30 PM Morgan Aldridge wrote: > >> > >> >Synopsis: pkg_add -IQ does not show single-line comment for packages matching query > >> >Category: system > >> >Environment: > >> System : OpenBSD 7.4 > >> Details : OpenBSD 7.4-stable (GENERIC.MP) #0: Sun Oct 29 17:05:47 EDT 2023 > >> linetrace@kuuki.winooski.vt.us.makkintosshu.net:/sys/arch/amd64/compile/GENERIC.MP > >> > >> Architecture: OpenBSD.amd64 > >> Machine : amd64 > >> >Description: > >> When using the pkg_info(1)'s '-Q' query option, it only displays the > >> package name and, appends " (installed)" if it's already installed. > >> There exists a '-I' option which will cause pkg_info(1) to display the > >> package name and the one-line comment describing the package. > >> Unfortunately, using the '-I' option with the '-Q' option doesn't > >> result in the one-line comment being included in the output. > >> > >> Looking at the implementation of pkg_info(1)'ss '-Q' option in > >> usr.sbin/pkg_add/OpenBSD/PkgInfo.pm, specifically handle_query(), it > >> calls $self->print_info() if any of the 'cdfMqs' options were provided, > >> otherwise just outputs the package name (denoting that it's installed, > >> if it is.) Interestingly, parse_and_run() explicitly adds the '-I' > >> option if it was not set along with the '-Q' option, but that's not one > >> of the options that handle_query() considers when branching into > >> print_info(). > >> >How-To-Repeat: > >> $ pkg_info -aQ vwm > >> debug-fvwm2-2.7.0 > >> debug-fvwm3-1.0.8p0 > >> fvwm2-2.7.0 > >> fvwm3-1.0.8p0 > >> mlvwm-0.9.4 (installed) > >> > >> $ pkg_info -qaQ vwm > >> debug-fvwm2-2.7.0 > >> debug-fvwm3-1.0.8p0 > >> fvwm2-2.7.0 > >> fvwm3-1.0.8p0 > >> mlvwm-0.9.4 > >> > >> $ pkg_info -IaQ vwm > >> debug-fvwm2-2.7.0 > >> debug-fvwm3-1.0.8p0 > >> fvwm2-2.7.0 > >> fvwm3-1.0.8p0 > >> mlvwm-0.9.4 (installed) > >> >Fix: > >> Untested: change handle_query() in usr.sbin/pkg_add/OpenBSD/PkgInfo.pm > >> to include the '-I' option when considering whether to call > >> $self->print_info(). This will likely allow the following functionality > >> (equivalent to `pkg_info -qaQ vwm | xargs pkg_info -I`): > >> > >> $ pkg_info -IaQ vwm > >> debug-fvwm2-2.7.0 debug info for fvwm2 > >> debug-fvwm3-1.0.8p0 debug info for fvwm3 > >> fvwm2-2.7.0 multiple virtual desktop window manager > >> fvwm3-1.0.8p0 multiple virtual desktop window manager > >> mlvwm-0.9.4 Macintosh-like virtual window manager > > > > The attached patch implements the above in a way that supports the current pkg_info(1) '-Q' functionality and allows combining with '-I'. Friendly ping on my proposed patch. It still applies cleanly, but below is an updated version anyway. I'm not subscribed to tech@, so please CC me on all replies. Index: PkgInfo.pm =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm,v retrieving revision 1.54 diff -u -p -u -p -r1.54 PkgInfo.pm --- PkgInfo.pm 25 Nov 2023 11:02:23 -0000 1.54 +++ PkgInfo.pm 1 May 2024 01:32:18 -0000 @@ -494,7 +494,7 @@ sub handle_query($self, $state) for my $pkg (sort {$a->name cmp $b->name} @$r) { my $p = $pkg->name; - if ($state->hasanyopt('cdfMqs')) { + if ($state->hasanyopt('cdfIMqs')) { $self->print_info($state, $p, $pkg); } else { $state->say( @@ -573,9 +573,7 @@ sub parse_and_run($self, $cmd) unless ($state->hasanyopt('cMUdfILRsSP') || $state->{terse}) { if ($nonames) { - if ($state->opt('Q')) { - $state->setopts('I'); - } else { + unless ($state->opt('Q')) { $state->setopts('Ia'); } } else {