summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2010-06-09 11:57:21 +0000
committerespie <espie@openbsd.org>2010-06-09 11:57:21 +0000
commitece832d9c15dd0929cb20c2a22f468debca518dc (patch)
treebf31b587d9acc0bde0837738123e2c94e0ca7f05 /usr.sbin/pkg_add
parentFix the pop operation to make PHP work again. When popping the last label (diff)
downloadwireguard-openbsd-ece832d9c15dd0929cb20c2a22f468debca518dc.tar.xz
wireguard-openbsd-ece832d9c15dd0929cb20c2a22f468debca518dc.zip
common pattern reuse
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm8
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgInfo.pm10
-rw-r--r--usr.sbin/pkg_add/OpenBSD/State.pm12
-rw-r--r--usr.sbin/pkg_add/pkg_merge8
-rw-r--r--usr.sbin/pkg_add/pkg_mklocatedb8
5 files changed, 22 insertions, 24 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm
index 5601fe9b403..c0a6a4b6363 100644
--- a/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm
+++ b/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: AddCreateDelete.pm,v 1.3 2010/06/09 07:26:01 espie Exp $
+# $OpenBSD: AddCreateDelete.pm,v 1.4 2010/06/09 11:57:21 espie Exp $
#
# Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org>
#
@@ -101,11 +101,9 @@ sub handle_options
$state->{subst}->parse_option(shift);
};
$state->usage_is(@usage);
- try {
+ $state->do_options(sub {
getopts('hmnvxD:'.$opt_string, $state->{opt});
- } catchall {
- $state->usage("#1", $_);
- };
+ });
$state->progress->setup($state->opt('x'), $state->opt('m'));
$state->{v} = $state->opt('v');
$state->{not} = $state->opt('n');
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm b/usr.sbin/pkg_add/OpenBSD/PkgInfo.pm
index ae3be9fac24..b91e8160d9a 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.3 2010/06/09 10:25:17 espie Exp $
+# $OpenBSD: PkgInfo.pm,v 1.4 2010/06/09 11:57:21 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -417,7 +417,7 @@ sub parse_and_run
my %defines;
my $locked;
- try {
+ $state->do_options(sub {
getopts('cCdfF:hIKLmPQ:qRsSUve:E:Ml:aAt',
{'e' =>
sub {
@@ -450,10 +450,8 @@ sub parse_and_run
push(@sought_files, File::Spec->rel2abs(shift));
}
- });
- } catchall {
- $state->usage("#1", $_);
- };
+ })
+ });
lock_db(1, $opt_q) unless $locked or $defines{nolock};
diff --git a/usr.sbin/pkg_add/OpenBSD/State.pm b/usr.sbin/pkg_add/OpenBSD/State.pm
index a9ac5876b2c..08b385d6678 100644
--- a/usr.sbin/pkg_add/OpenBSD/State.pm
+++ b/usr.sbin/pkg_add/OpenBSD/State.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: State.pm,v 1.1 2010/06/09 07:26:01 espie Exp $
+# $OpenBSD: State.pm,v 1.2 2010/06/09 11:57:21 espie Exp $
#
# Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org>
#
@@ -102,4 +102,14 @@ sub errsay
print STDERR $self->f(@_), "\n";
}
+sub do_options
+{
+ my ($state, $sub) = @_;
+ require OpenBSD::Error;
+ # this could be nicer...
+ eval { &$sub; };
+ OpenBSD::Error::dienow($@,
+ bless sub { $state->usage("#1", $_)}, "OpenBSD::Error::catchall");
+}
+
1;
diff --git a/usr.sbin/pkg_add/pkg_merge b/usr.sbin/pkg_add/pkg_merge
index bb4c70f2c82..b65ac17eb0d 100644
--- a/usr.sbin/pkg_add/pkg_merge
+++ b/usr.sbin/pkg_add/pkg_merge
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# Copyright (c) 2005-2007 Marc Espie <espie@openbsd.org>
-# $OpenBSD: pkg_merge,v 1.15 2010/06/09 10:58:01 espie Exp $
+# $OpenBSD: pkg_merge,v 1.16 2010/06/09 11:57:21 espie Exp $
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -133,11 +133,7 @@ $ui->usage_is('[-v] -o result pkg pkg2 ...');
our ($opt_o, $opt_v);
-try {
- getopts('o:v');
-} catchall {
- $ui->usage($_);
-};
+$ui->do_options(sub { getopts('o:v'); });
if (!defined $opt_o) {
$ui->usage("Missing -o result");
diff --git a/usr.sbin/pkg_add/pkg_mklocatedb b/usr.sbin/pkg_add/pkg_mklocatedb
index 39d2b7c0ee1..2f4353137b1 100644
--- a/usr.sbin/pkg_add/pkg_mklocatedb
+++ b/usr.sbin/pkg_add/pkg_mklocatedb
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# Copyright (c) 2005-2010 Marc Espie <espie@openbsd.org>
-# $OpenBSD: pkg_mklocatedb,v 1.25 2010/06/09 10:58:01 espie Exp $
+# $OpenBSD: pkg_mklocatedb,v 1.26 2010/06/09 11:57:21 espie Exp $
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -73,11 +73,7 @@ sub tag
return $r;
}
-try {
- getopts('ad:nqs:x:r:p:P');
-} catchall {
- $ui->usage($_);
-};
+$ui->do_options(sub { getopts('ad:nqs:x:r:p:P'); });
my $fh;
my $MKLOCATEDB = OpenBSD::Paths->mklocatedb;