summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2020-02-19 14:23:26 +0000
committerespie <espie@openbsd.org>2020-02-19 14:23:26 +0000
commit9944c58cf8ad3b4e7872849c2bac6a565b1a5bc6 (patch)
tree837775039ff1ccfcc87169ce76d95608153c4128 /usr.sbin/pkg_add
parentallow search objects to say "keep_all" and make PackageRepositoryLists (diff)
downloadwireguard-openbsd-9944c58cf8ad3b4e7872849c2bac6a565b1a5bc6.tar.xz
wireguard-openbsd-9944c58cf8ad3b4e7872849c2bac6a565b1a5bc6.zip
refactor opt('Q') into its own code
make sure we see -a along with opt('Q') tweak -aQ to use keep_all so that it shows every entry in every repository instead of stopping at the first one.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgInfo.pm51
1 files changed, 32 insertions, 19 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm b/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm
index 7423e32e35f..81001083ee9 100644
--- a/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: PkgInfo.pm,v 1.49 2017/10/07 13:23:05 espie Exp $
+# $OpenBSD: PkgInfo.pm,v 1.50 2020/02/19 14:23:26 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
@@ -513,6 +513,31 @@ sub print_info
}
}
+sub handle_query
+{
+ my ($self, $state) = @_;
+
+ require OpenBSD::Search;
+
+ $state->say("PKG_PATH=#1", $ENV{PKG_PATH} // "<undefined>")
+ if $state->verbose;
+ my $partial = OpenBSD::Search::PartialStem->new($state->opt('Q'));
+ if ($state->opt('a')) {
+ $partial->keep_all;
+ }
+ my $r = $state->repo->match_locations($partial);
+
+ for my $pkg (sort {$a->name cmp $b->name} @$r) {
+ my $p = $pkg->name;
+ if ($state->hasanyopt('cdfMqs')) {
+ $self->print_info($state, $p, $pkg);
+ } else {
+ $state->say(
+ is_installed($p) ? "#1 (installed)" : "#1", $p);
+ }
+ }
+}
+
sub parse_and_run
{
my ($self, $cmd) = @_;
@@ -585,30 +610,18 @@ sub parse_and_run
unless ($state->hasanyopt('cMUdfILRsSP') || $state->{terse}) {
if ($nonames) {
- $state->setopts('Ia');
+ if ($state->opt('Q')) {
+ $state->setopts('I');
+ } else {
+ $state->setopts('Ia');
+ }
} else {
$state->setopts('cdMR');
}
}
if ($state->opt('Q')) {
- require OpenBSD::Search;
-
- $state->say("PKG_PATH=#1", $ENV{PKG_PATH} // "<undefined>")
- if $state->verbose;
- my $partial = OpenBSD::Search::PartialStem->new($state->opt('Q'));
- my $r = $state->repo->match_locations($partial);
-
- for my $pkg (sort {$a->name cmp $b->name} @$r) {
- my $p = $pkg->name;
- if ($state->hasanyopt('cdfMqs')) {
- $self->print_info($state, $p, $pkg);
- } else {
- $state->say(
- is_installed($p) ? "#1 (installed)" : "#1", $p);
- }
- }
-
+ $self->handle_query($state);
return 0;
}