diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2010-06-25 11:12:15 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2010-06-25 11:12:15 +0000 |
commit | 303b09a8aa986d37874d26cb7d4f668437266759 (patch) | |
tree | 6f99aeab066a5b8604768bbf79ca7ccb40b343ba | |
parent | ee080cb386103863da44c324cca09accbccb7cd3 (diff) |
clean-up options handling some more
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/AddDelete.pm | 16 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PkgAdd.pm | 119 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PkgDelete.pm | 43 |
3 files changed, 84 insertions, 94 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm index 74c75a549fd..19edd166924 100644 --- a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm +++ b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: AddDelete.pm,v 1.28 2010/06/25 10:54:28 espie Exp $ +# $OpenBSD: AddDelete.pm,v 1.29 2010/06/25 11:12:14 espie Exp $ # # Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org> # @@ -29,16 +29,6 @@ use OpenBSD::Paths; use OpenBSD::PackageInfo; use OpenBSD::AddCreateDelete; -sub handle_options -{ - my ($self, $opt_string, $hash, $cmd, @usage) = @_; - - my $state = $self->new_state($cmd); - $state->{opt} = $hash; - $state->handle_options($opt_string, @usage); - return $state; -} - sub do_the_main_work { my ($self, $state) = @_; @@ -102,7 +92,8 @@ sub parse_and_run { my ($self, $cmd) = @_; - my $state = $self->handle_options($cmd); + my $state = $self->new_state($cmd); + $state->handle_options; local $SIG{'INFO'} = sub { $state->status->print($state); }; $self->framework($state); @@ -146,6 +137,7 @@ sub handle_options $state->{subst}->add($o, 1); } }; + $state->{no_exports} = 1; $state->SUPER::handle_options($opt_string.'ciInqsB:F:', @usage); if ($state->opt('s')) { diff --git a/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm index c91c462d1b2..febf5d9aec5 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: PkgAdd.pm,v 1.4 2010/06/15 08:20:44 espie Exp $ +# $OpenBSD: PkgAdd.pm,v 1.5 2010/06/25 11:12:14 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -65,6 +65,64 @@ sub has_different_sig package OpenBSD::PkgAdd::State; our @ISA = qw(OpenBSD::AddDelete::State); +sub handle_options +{ + my $state = shift; + $state->SUPER::handle_options('aruUzl:A:P:Q:', + '[-acIinqrsUuvxz] [-A arch] [-B pkg-destdir] [-D name[=value]]', + '[-L localbase] [-l file] [-P type] [-Q quick-destdir] pkg-name [...]'); + + $state->{do_faked} = 0; + $state->{arch} = $state->opt('A'); + + if (defined $state->opt('Q') and defined $state->opt('B')) { + $state->usage("-Q and -B are incompatible options"); + } + if (defined $state->opt('Q') and defined $state->opt('r')) { + $state->usage("-r and -Q are incompatible options"); + } + if ($state->opt('P')) { + if ($state->opt('P') eq 'cdrom') { + $state->{cdrom_only} = 1; + } + elsif ($state->opt('P') eq 'ftp') { + $state->{ftp_only} = 1; + } + else { + $state->usage("bad option: -P #1", $state->opt('P')); + } + } + if (defined $state->opt('Q')) { + $state->{destdir} = $state->opt('Q'); + $state->{do_faked} = 1; + } elsif (defined $state->opt('B')) { + $state->{destdir} = $state->opt('B'); + } elsif (defined $ENV{'PKG_PREFIX'}) { + $state->{destdir} = $ENV{'PKG_PREFIX'}; + } + if (defined $state->{destdir}) { + $state->{destdir}.='/'; + $ENV{'PKG_DESTDIR'} = $state->{destdir}; + } else { + $state->{destdir} = ''; + delete $ENV{'PKG_DESTDIR'}; + } + + + $state->{automatic} = $state->opt('a'); + $state->{hard_replace} = $state->opt('r'); + $state->{newupdates} = $state->opt('u') || $state->opt('U'); + $state->{allow_replacing} = $state->{hard_replace} || + $state->{newupdates}; + $state->{pkglist} = $state->opt('l'); + $state->{update} = $state->opt('u'); + $state->{fuzzy} = $state->opt('z'); + + if (@ARGV == 0 && !$state->{update} && !$state->{pkglist}) { + $state->usage("Missing pkgname"); + } +} + # one-level dependencies tree, for nicer printouts sub build_deptree { @@ -996,65 +1054,6 @@ sub finish_display inform_user_of_problems($state); } -sub handle_options -{ - my ($self, $cmd) = @_; - my $state = $self->SUPER::handle_options('aruUzl:A:P:Q:', {}, $cmd, - '[-acIinqrsUuvxz] [-A arch] [-B pkg-destdir] [-D name[=value]]', - '[-L localbase] [-l file] [-P type] [-Q quick-destdir] pkg-name [...]'); - - $state->{do_faked} = 0; - $state->{arch} = $state->opt('A'); - - if (defined $state->opt('Q') and defined $state->opt('B')) { - $state->usage("-Q and -B are incompatible options"); - } - if (defined $state->opt('Q') and defined $state->opt('r')) { - $state->usage("-r and -Q are incompatible options"); - } - if ($state->opt('P')) { - if ($state->opt('P') eq 'cdrom') { - $state->{cdrom_only} = 1; - } - elsif ($state->opt('P') eq 'ftp') { - $state->{ftp_only} = 1; - } - else { - $state->usage("bad option: -P #1", $state->opt('P')); - } - } - if (defined $state->opt('Q')) { - $state->{destdir} = $state->opt('Q'); - $state->{do_faked} = 1; - } elsif (defined $state->opt('B')) { - $state->{destdir} = $state->opt('B'); - } elsif (defined $ENV{'PKG_PREFIX'}) { - $state->{destdir} = $ENV{'PKG_PREFIX'}; - } - if (defined $state->{destdir}) { - $state->{destdir}.='/'; - $ENV{'PKG_DESTDIR'} = $state->{destdir}; - } else { - $state->{destdir} = ''; - delete $ENV{'PKG_DESTDIR'}; - } - - - $state->{automatic} = $state->opt('a'); - $state->{hard_replace} = $state->opt('r'); - $state->{newupdates} = $state->opt('u') || $state->opt('U'); - $state->{allow_replacing} = $state->{hard_replace} || - $state->{newupdates}; - $state->{pkglist} = $state->opt('l'); - $state->{update} = $state->opt('u'); - $state->{fuzzy} = $state->opt('z'); - - if (@ARGV == 0 && !$state->{update} && !$state->{pkglist}) { - $state->usage("Missing pkgname"); - } - return $state; -} - sub main { my ($self, $state) = @_; diff --git a/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm b/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm index 20234bfa8ca..1e046e87407 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm @@ -1,6 +1,6 @@ #!/usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: PkgDelete.pm,v 1.5 2010/06/15 08:21:05 espie Exp $ +# $OpenBSD: PkgDelete.pm,v 1.6 2010/06/25 11:12:14 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -24,6 +24,26 @@ use OpenBSD::AddDelete; package OpenBSD::PkgDelete::State; our @ISA = qw(OpenBSD::AddDelete::State); +sub handle_options +{ + my $state = shift; + $state->SUPER::handle_options('', + '[-cIinqsvx] [-B pkg-destdir] [-D name[=value]] pkg-name [...]'); + + my $base = $state->opt('B') // $ENV{'PKG_DESTDIR'} // ''; + if ($base ne '') { + $base.='/' unless $base =~ m/\/$/o; + } + $ENV{'PKG_DESTDIR'} = $base; + + $state->{destdir} = $base; + if ($base eq '') { + $state->{destdirname} = ''; + } else { + $state->{destdirname} = '${PKG_DESTDIR}'; + } +} + sub todo { my ($state, $offset) = @_; @@ -97,27 +117,6 @@ sub finish_display { } -sub handle_options -{ - my ($self, $cmd) = @_; - my $state = $self->SUPER::handle_options('', {}, $cmd, - '[-cIinqsvx] [-B pkg-destdir] [-D name[=value]] pkg-name [...]'); - - my $base = $state->opt('B') // $ENV{'PKG_DESTDIR'} // ''; - if ($base ne '') { - $base.='/' unless $base =~ m/\/$/o; - } - $ENV{'PKG_DESTDIR'} = $base; - - $state->{destdir} = $base; - if ($base eq '') { - $state->{destdirname} = ''; - } else { - $state->{destdirname} = '${PKG_DESTDIR}'; - } - return $state; -} - sub main { my ($self, $state) = @_; |