diff options
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm index 554dfe0380f..76122626c68 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.25 2014/06/03 13:13:53 espie Exp $ +# $OpenBSD: AddCreateDelete.pm,v 1.26 2014/11/29 10:42:51 espie Exp $ # # Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org> # @@ -65,10 +65,45 @@ sub handle_options { my ($state, $opt_string, @usage) = @_; - $state->SUPER::handle_options($opt_string.'L:mnx', @usage); + $state->SUPER::handle_options($opt_string.'IiL:mnx', @usage); $state->progress->setup($state->opt('x'), $state->opt('m'), $state); $state->{not} = $state->opt('n'); + if ($state->opt('i') && $state->opt('I')) { + $state->usage("-i and -I are reverse options, make up your mind"); + } + my $i; + if ($state->opt('i')) { + $i = 1; + } elsif ($state->opt('I')) { + $i = 0; + } else { + $i = -t STDIN; + } + if ($i) { + require OpenBSD::Interactive; + $state->{interactive} = OpenBSD::Interactive->new($state); + } else { + $state->{interactive} = OpenBSD::InteractiveStub->new($state); + } +} + + +sub is_interactive +{ + return shift->{interactive}->is_interactive; +} + +sub confirm +{ + my $self = shift; + return $self->{interactive}->confirm(@_); +} + +sub ask_list +{ + my $self = shift; + return $self->{interactive}->ask_list(@_); } sub vsystem @@ -140,4 +175,27 @@ sub handle_options $state->handle_options($opt_string, $self, @usage); } +package OpenBSD::InteractiveStub; +sub new +{ + my $class = shift; + bless {}, $class; +} + +sub ask_list +{ + my ($self, $prompt, @values) = @_; + return $values[0]; +} + +sub confirm +{ + my ($self, $prompt, $yesno) = @_; + return $yesno; +} + +sub is_interactive +{ + return 0; +} 1; |