diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2004-12-06 12:35:37 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2004-12-06 12:35:37 +0000 |
commit | 5bdb7a1f65ec91239613dfe6c0e7daae9204af1e (patch) | |
tree | 40fde354c2c6cc5e036daf7be2a54ca311c71142 /usr.sbin | |
parent | b528e2efc28e96840ad933398c9d8802737b97a0 (diff) |
Usage
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Error.pm | 26 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 24 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_create | 35 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_delete | 21 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_info | 19 |
5 files changed, 93 insertions, 32 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Error.pm b/usr.sbin/pkg_add/OpenBSD/Error.pm index 7498bb35865..daffc2e52c9 100644 --- a/usr.sbin/pkg_add/OpenBSD/Error.pm +++ b/usr.sbin/pkg_add/OpenBSD/Error.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Error.pm,v 1.7 2004/11/27 12:07:58 espie Exp $ +# $OpenBSD: Error.pm,v 1.8 2004/12/06 12:35:36 espie Exp $ # # Copyright (c) 2004 Marc Espie <espie@openbsd.org> # @@ -20,7 +20,7 @@ use warnings; package OpenBSD::Error; our @ISA=qw(Exporter); -our @EXPORT=qw(System VSystem Copy Fatal Warn); +our @EXPORT=qw(System VSystem Copy Fatal Warn Usage set_usage); sub System { @@ -131,4 +131,26 @@ sub system $state->print("system(", join(", ", @_), ") was not run: $! $?\n"); } } + +my @usage_line; + +sub set_usage +{ + @usage_line = @_; +} + +sub Usage +{ + my $code = 0; + if (@_) { + print STDERR "Error: ", @_, "\n"; + $code = 1; + } + print STDERR "Usage: ", shift(@usage_line), "\n"; + for my $l (@usage_line) { + print STDERR " $l\n"; + } + exit($code); +} + 1; diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 5c001d1734e..a0e1af008ab 100644 --- a/usr.sbin/pkg_add/pkg_add +++ b/usr.sbin/pkg_add/pkg_add @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_add,v 1.132 2004/12/02 00:04:38 espie Exp $ +# $OpenBSD: pkg_add,v 1.133 2004/12/06 12:35:36 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -599,15 +599,24 @@ sub install_package return (); } +set_usage('pkg_add [-acInqrvvx] [-A arch] [-B pkg-destdir] [-f keys] [-L localbase] [-P type] [-Q quick-destdir] pkgname [...]'); + our ($opt_a, $opt_v, $opt_n, $opt_I, $opt_L, $opt_B, $opt_A, $opt_P, $opt_Q, $opt_x, $opt_r, $opt_q, $opt_c); $opt_v = 0; -getopts('aqcvnrxIL:f:B:A:P:Q:', +eval { getopts('aqchvnrxIL:f:B:A:P:Q:', {'v' => sub {++$opt_v;}, + 'h' => sub { Usage(); }, 'f' => sub { for my $o (split/,/, shift) { $forced{$o} = 1; } - }}); + }}); }; +if ($@) { + chomp($@); + $@ =~ s/\s+at.*?$//; + Usage($@); +} + $opt_L = '/usr/local' unless defined $opt_L; my $state = new OpenBSD::Error; @@ -620,10 +629,10 @@ $state->{arch} = $opt_A; $state->{forced} = \%forced; if (defined $opt_Q and defined $opt_B) { - Fatal "-Q and -B are incompatible options"; + Usage "-Q and -B are incompatible options"; } if (defined $opt_Q and defined $opt_r) { - Fatal "-r and -Q are incompatible options"; + Usage "-r and -Q are incompatible options"; } if ($opt_P) { if ($opt_P eq 'cdrom') { @@ -633,7 +642,7 @@ if ($opt_P) { $state->{ftp_only} = 1; } else { - Fatal "bad option: -P $opt_P"; + Usage "bad option: -P $opt_P"; } } if (defined $opt_Q) { @@ -700,5 +709,6 @@ if ($state->{beverbose}) { } $state->delayed_output(); if ($dielater) { - die $dielater; + print STDERR $dielater; + exit(1); } diff --git a/usr.sbin/pkg_add/pkg_create b/usr.sbin/pkg_add/pkg_create index d4ef1911e50..aeb58306512 100644 --- a/usr.sbin/pkg_add/pkg_create +++ b/usr.sbin/pkg_add/pkg_create @@ -1,6 +1,6 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_create,v 1.27 2004/12/02 18:32:37 espie Exp $ +# $OpenBSD: pkg_create,v 1.28 2004/12/06 12:35:36 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -272,8 +272,15 @@ our ($opt_p, $opt_f, $opt_c, $opt_d, $opt_v, $opt_i, $opt_k, $opt_r, my @contents; my $regen_package = 0; +set_usage( +'pkg_create [-hnv] [-A arches] [-B pkg-destdir] [-Dname=value]', +'[-i iscript] [-k dscript] [-L localbase] [-M displayfile] [-P pkg-dep]', +'[-p prefix] [-r rscript] [-S pkg-destdir] [-U undisplayfile]', +'[-W wantedlib] -c desc -d desc -f packinglist pkgname', +'pkg_create [-hnv] -f installed-packinglist'); + my $plist = new OpenBSD::PackingList; -getopts('p:f:c:d:vi:k:r:M:U:S:hs:OA:L:B:D:P:W:n', +eval { getopts('hp:f:c:d:vi:k:r:M:U:S:hs:OA:L:B:D:P:W:n', {'D' => sub { local $_ = shift; @@ -287,33 +294,39 @@ getopts('p:f:c:d:vi:k:r:M:U:S:hs:OA:L:B:D:P:W:n', sub { push(@contents, shift); }, + 'h' => sub { Usage(); }, 'P' => sub { OpenBSD::PackingElement::Dependency->add($plist, shift); }, 'W' => sub { OpenBSD::PackingElement::Wantlib->add($plist, shift); } - }); + }); }; +if ($@) { + chomp($@); + $@ =~ s/\s+at.*?$//; + Usage($@); +} if (@ARGV == 0) { $regen_package = 1; } elsif (@ARGV != 1) { - die "Exactly one single package name is required"; + Usage "Exactly one single package name is required"; } my $dir = OpenBSD::Temp::dir(); my $dir2 = $dir; if (defined $opt_s) { - die "Option s is no longer supported"; + Usage "Option s is no longer supported"; } if (defined $opt_O) { - die "Option O is no longer supported"; + Usage "Option O is no longer supported"; } if (!@contents) { - die "Packing list required"; + Usage "Packing list required"; } if (defined $opt_c) { @@ -325,7 +338,7 @@ if (defined $opt_c) { copy_subst($opt_c, $dir.COMMENT); } } else { - die "Comment required" unless $regen_package; + Usage "Comment required" unless $regen_package; } if (defined $opt_d) { @@ -337,7 +350,7 @@ if (defined $opt_d) { copy_subst($opt_d, $dir.DESC); } } else { - die "Description required" unless $regen_package; + Usage "Description required" unless $regen_package; } print "Creating package $ARGV[0]\n" if $opt_v && !$regen_package; @@ -374,7 +387,7 @@ for my $special (info_names()) { if (defined $opt_p) { OpenBSD::PackingElement::Cwd->add($plist, $opt_p); } elsif (!$regen_package) { - die "Prefix required"; + Usage "Prefix required"; } if (!$regen_package && $ARGV[0] =~ m|([^/]+)$|) { @@ -395,7 +408,7 @@ if ($regen_package) { my $v = 0; $plist->visit('anything', \$v); if ($v != 0 || @contents != 1) { - die "Exactly one single package name is required"; + Usage "Exactly one single package name is required"; } $dir = dirname($contents[0]); } diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete index ec8d5424806..4aabf1e6735 100644 --- a/usr.sbin/pkg_add/pkg_delete +++ b/usr.sbin/pkg_add/pkg_delete @@ -1,6 +1,6 @@ #!/usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_delete,v 1.79 2004/11/15 11:39:05 espie Exp $ +# $OpenBSD: pkg_delete,v 1.80 2004/12/06 12:35:36 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -29,17 +29,25 @@ use OpenBSD::PackageInfo; our %forced = (); +set_usage('pkg_delete [-cInqvx] [-B pkg-destdir] [-f keys] pkgname [...]'); our ($opt_v, $opt_D, $opt_d, $opt_n, $opt_q, $opt_p, $opt_c, $opt_L, $opt_B, $opt_I, $opt_x); $opt_v = 0; -getopts('vcxDdnf:qpS:L:B:I', +eval { getopts('vchxDdnf:qpS:L:B:I', {'v' => sub {++$opt_v;}, + 'h' => sub { Usage(); }, 'f' => sub { for my $o (split/,/, shift) { $forced{$o} = 1; } - }}); + }}); }; +if ($@) { + chomp($@); + $@ =~ s/\s+at.*?$//; + Usage($@); +} + if ($opt_D) { $opt_I = 1; } @@ -53,10 +61,10 @@ $ENV{'PKG_DESTDIR'} = $opt_B; $opt_L = '/usr/local' unless defined $opt_L; if (defined $opt_p) { - Fatal "Option p is obsolete"; + Usage "Option p is obsolete"; } if (defined $opt_d) { - Fatal "Option d is obsolete"; + Usage "Option d is obsolete"; } my %done; @@ -204,5 +212,6 @@ if ($state->{beverbose}) { } $state->delayed_output(); if ($dielater) { - die $dielater; + print STDERR $dielater; + exit(1); } diff --git a/usr.sbin/pkg_add/pkg_info b/usr.sbin/pkg_add/pkg_info index 1216e373809..32e20651632 100644 --- a/usr.sbin/pkg_add/pkg_info +++ b/usr.sbin/pkg_add/pkg_info @@ -1,6 +1,6 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_info,v 1.21 2004/11/15 12:58:48 espie Exp $ +# $OpenBSD: pkg_info,v 1.22 2004/12/06 12:35:36 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -244,7 +244,9 @@ sub print_info } } -getopts('cDdfIikKLmpqRrsvhe:E:MU:l:aA', +set_usage('pkg_info [-cDdfIiKkLMpqRrsUv] [-E fname] [-e pkgname] [-l str] pkgname...', 'pkg_info [-Aa flags]'); + +eval { getopts('cDdfIikKLmpqRrsvhe:E:MU:l:aA', {'e' => sub { my $pat = shift; @@ -267,7 +269,12 @@ getopts('cDdfIikKLmpqRrsvhe:E:MU:l:aA', push(@sought_files, File::Spec->rel2abs(shift)); } - }); + }); }; +if ($@) { + chomp($@); + $@ =~ s/\s+at.*?$//; + Usage($@); +} if ($opt_D) { $opt_M = 1; @@ -292,15 +299,15 @@ if (!defined $opt_l) { } if ($opt_K && !$opt_L) { - Fatal "-K only makes sense with -L"; + Usage "-K only makes sense with -L"; } if (@ARGV == 0 && !$opt_a && !$opt_A) { - Fatal "Missing package name(s)" unless $terse && $opt_q; + Usage "Missing package name(s)" unless $terse && $opt_q; } if (@ARGV > 0 && ($opt_a || $opt_A)) { - Fatal "Can't specify package name(s) with -a"; + Usage "Can't specify package name(s) with -a"; } if (@ARGV == 0) { |