From 34efd479fa8bad945ccf900ff7b2ea62520b5ab9 Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Fri, 1 Jun 2007 14:58:30 +0000 Subject: refactor ProgressMeter code to create objects, put these into state. Create a common state class for delete and add, put the progressmeter creation in there. neat effect: we don't have a progressmeter, we use a stub class instead and *never* pull the code in at all. --- usr.sbin/pkg_add/pkg_delete | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'usr.sbin/pkg_add/pkg_delete') diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete index 3da5a1f66a8..8f8fc3b879d 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.105 2007/05/31 13:33:17 espie Exp $ +# $OpenBSD: pkg_delete,v 1.106 2007/06/01 14:58:29 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie # @@ -22,7 +22,6 @@ use OpenBSD::Getopt; use OpenBSD::PackingList; use OpenBSD::RequiredBy; use OpenBSD::Error; -use OpenBSD::ProgressMeter; use OpenBSD::Interactive; use OpenBSD::Delete; use OpenBSD::PackageInfo; @@ -33,7 +32,7 @@ our %forced = (); our $not; package OpenBSD::pkg_delete::State; -our @ISA=(qw(OpenBSD::Error)); +our @ISA=(qw(OpenBSD::pkg_foo::State)); package main; @@ -106,17 +105,8 @@ if ($opt_B eq '') { $ENV{'PKG_DELETE_EXTRA'} = $state->{extra} ? "Yes" : "No"; lock_db($opt_n); -if (!$opt_x && !$state->{beverbose}) { - OpenBSD::ProgressMeter::enable(); -} - -if ($< && !$forced{nonroot}) { - if ($state->{not}) { - Warn "$0 should be run as root\n"; - } else { - Fatal "$0 must be run as root"; - } -} +$state->setup_progressmeter($opt_x); +$state->check_root; # First, resolve pkg names @@ -193,7 +183,7 @@ eval { next; } } - if (!OpenBSD::ProgressMeter::set_header($pkgname)) { + if (!$state->progress->set_header($pkgname)) { print $opt_n ? "Pretending to delete " : "Deleting ", "$pkgname\n"; } -- cgit v1.2.3