diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2009-10-14 10:38:07 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2009-10-14 10:38:07 +0000 |
commit | d8b6ed5e3e9c841e156a3ae99b8a7482a508e7c3 (patch) | |
tree | 612abeac9202a7999655cad395b011617008a654 /usr.sbin/pkg_add | |
parent | 8c47039dd0398cab14e93383e198d14b3782e0a0 (diff) |
add a "print" method to ProgressMeter and StubProgress to allow me to clean
up the current mess (e.g., print things out to stderr without needing to
explicitly clear the current line if needed).
create a choose_location method directly in state, that will replace all
instances of looking for a package eventually (hopefully).
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm | 8 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/UpdateSet.pm | 33 |
2 files changed, 39 insertions, 2 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm b/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm index 0f9249bf659..47d91dbba23 100644 --- a/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm +++ b/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: ProgressMeter.pm,v 1.11 2007/06/01 14:58:29 espie Exp $ +# $OpenBSD: ProgressMeter.pm,v 1.12 2009/10/14 10:38:06 espie Exp $ # # Copyright (c) 2004-2007 Marc Espie <espie@openbsd.org> # @@ -130,6 +130,12 @@ sub clear print STDERR ' 'x length($lastdisplay), "\r"; } +sub print +{ + shift->clear; + print STDERR @_; +} + sub next { my $self = shift; diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm index 3bc63486dbd..f17f5c18cb4 100644 --- a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm +++ b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: UpdateSet.pm,v 1.6 2009/10/11 10:53:39 espie Exp $ +# $OpenBSD: UpdateSet.pm,v 1.7 2009/10/14 10:38:06 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -71,6 +71,31 @@ sub check_root } } +sub choose_location +{ + my ($state, $name, $list) = @_; + if (@$list == 0) { + $state->progress->print("Can't find $name\n"); + return undef; + } elsif (@$list == 1) { + return $list->[0]; + } + + my %h = map {($_->name, $_)} @$list; + if ($state->{interactive}) { + require OpenBSD::Interactive; + + $h{'<None>'} = undef; + $state->progress->clear; + my $result = OpenBSD::Interactive::ask_list("Ambiguous: choose package for $name", 1, sort keys %h); + return $h{$result}; + } else { + $state->progress->print("Ambiguous: $name could be ", + join(' ', keys %h), "\n"); + return undef; + } +} + package OpenBSD::StubProgress; sub clear {} @@ -82,6 +107,12 @@ sub next {} sub set_header {} +sub print +{ + shift; + print STDERR @_; +} + # fairly non-descriptive name. Used to store various package information # during installs and updates. package OpenBSD::Handle; |