diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2016-06-15 15:40:14 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2016-06-15 15:40:14 +0000 |
commit | da652f45a375063ead4eb9d50663ac196cf69f06 (patch) | |
tree | 07ca8781345a78610ff381acabda7542f9fb11f1 | |
parent | 0353d7975bcf238fa0f71605261fcf9408afd8b4 (diff) |
dedup interactive options handling code yet again.
dynamic code mixin
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm | 31 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/AddDelete.pm | 16 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PkgCheck.pm | 18 |
3 files changed, 34 insertions, 31 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm index e380c26c1eb..e61677d033f 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.36 2016/06/06 15:19:45 espie Exp $ +# $OpenBSD: AddCreateDelete.pm,v 1.37 2016/06/15 15:40:13 espie Exp $ # # Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org> # @@ -55,15 +55,42 @@ sub sync_display $self->progress->clear; } +sub add_interactive_options +{ + my $self = shift; + $self->{has_interactive_options} = 1; + return $self; +} + sub handle_options { my ($state, $opt_string, @usage) = @_; + my $i; + + if ($state->{has_interactive_options}) { + $opt_string .= 'iI'; + $state->{opt}{i} = sub { + $i++; + }; + }; + $state->SUPER::handle_options($opt_string.'L:mnx', @usage); $state->progress->setup($state->opt('x'), $state->opt('m'), $state); $state->{not} = $state->opt('n'); - $state->{interactive} = OpenBSD::InteractiveStub->new($state); + if ($state->{has_interactive_options}) { + if ($state->opt('I')) { + $i = 0; + } elsif (!defined $i) { + $i = -t STDIN; + } + } + if ($i) { + require OpenBSD::Interactive; + $state->{interactive} = OpenBSD::Interactive->new($state, $i); + } + $state->{interactive} //= OpenBSD::InteractiveStub->new($state); } diff --git a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm index 9dee061c7b6..a889f49c0cc 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.73 2016/06/06 13:58:55 espie Exp $ +# $OpenBSD: AddDelete.pm,v 1.74 2016/06/15 15:40:13 espie Exp $ # # Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org> # @@ -167,25 +167,13 @@ sub handle_options $state->{subst}->add($o, 1); } }; - my $i; - $state->{opt}{i} //= sub { - $i++; - }; $state->{no_exports} = 1; + $state->add_interactive_options; $state->SUPER::handle_options($opt_string.'aciInqsB:F:', @usage); if ($state->opt('s')) { $state->{not} = 1; } - if ($state->opt('I')) { - $i = 0; - } elsif (!defined $i) { - $i = -t STDIN; - } - if ($i) { - require OpenBSD::Interactive; - $state->{interactive} = OpenBSD::Interactive->new($state, $i); - } # XXX RequiredBy $main::not = $state->{not}; $state->{localbase} = $state->opt('L') // OpenBSD::Paths->localbase; diff --git a/usr.sbin/pkg_add/OpenBSD/PkgCheck.pm b/usr.sbin/pkg_add/OpenBSD/PkgCheck.pm index ae26853c0f4..27782aa7b24 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgCheck.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgCheck.pm @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: PkgCheck.pm,v 1.58 2016/06/06 15:19:45 espie Exp $ +# $OpenBSD: PkgCheck.pm,v 1.59 2016/06/15 15:40:13 espie Exp $ # # Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org> # @@ -306,23 +306,11 @@ sub safe sub handle_options { my $self = shift; - my $i; - $self->{opt}{i} //= sub { - $i++; - }; $self->{no_exports} = 1; - $self->SUPER::handle_options('iIfB:q', + $self->add_interactive_options; + $self->SUPER::handle_options('fB:q', '[-fIimnqvx] [-B pkg-destdir] [-D value]'); - if ($self->opt('I')) { - $i = 0; - } elsif (!defined $i) { - $i = -t STDIN; - } - if ($i) { - require OpenBSD::Interactive; - $self->{interactive} = OpenBSD::Interactive->new($self, $i); - } $self->{force} = $self->opt('f'); $self->{quick} = $self->opt('q'); if (defined $self->opt('B')) { |