The following diff adds "-y" support in pkg_delete and pkg_add. The option is quit simple when a yes/no prompt would be presented, assume that the user entered "yes". I often need that for pkg_delete when I work on KDE updates.
A simple example: $ doas pkg_delete prison-kf5-5.76.0 can't delete prison-kf5-5.76.0 without deleting akonadi-contacts-20.08.3 Delete them as well ? [y/N/a] $ doas pkg_delete -y prison-kf5-5.76.0 can't delete prison-kf5-5.76.0 without deleting akonadi-contacts-20.08.3 can't delete akonadi-contacts-20.08.3 without deleting digikam-7.1.0p0 digikam-7.1.0p0: ok akonadi-contacts-20.08.3: ok prison-kf5-5.76.0: ok Running tags: ok Read shared items: ok Feedback, Ok? Rafael Index: pkg_add.1 =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/pkg_add.1,v retrieving revision 1.163 diff -u -p -r1.163 pkg_add.1 --- pkg_add.1 24 Jan 2020 21:10:46 -0000 1.163 +++ pkg_add.1 27 Nov 2020 06:38:45 -0000 @@ -502,6 +502,8 @@ also shows dependencies adjustments, and shows everything. .It Fl x Disable progress meter. +.It Fl y +When a yes/no prompt would be presented, assume that the user entered "yes". .It Fl z Fuzzy package addition: .Nm Index: pkg_delete.1 =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/pkg_delete.1,v retrieving revision 1.59 diff -u -p -r1.59 pkg_delete.1 --- pkg_delete.1 10 Jul 2018 10:20:51 -0000 1.59 +++ pkg_delete.1 27 Nov 2020 06:38:45 -0000 @@ -169,6 +169,8 @@ shows everything. Delete everything, except the list of packages that follow. .It Fl x Disable progress meter. +.It Fl y +When a yes/no prompt would be presented, assume that the user entered "yes". .El .Sh TECHNICAL DETAILS .Nm Index: OpenBSD/AddCreateDelete.pm =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm,v retrieving revision 1.48 diff -u -p -r1.48 AddCreateDelete.pm --- OpenBSD/AddCreateDelete.pm 11 Jan 2020 13:46:39 -0000 1.48 +++ OpenBSD/AddCreateDelete.pm 27 Nov 2020 06:38:45 -0000 @@ -88,9 +88,11 @@ sub handle_options } if ($i) { require OpenBSD::Interactive; - $state->{interactive} = OpenBSD::Interactive->new($state, $i); + $state->{interactive} = OpenBSD::Interactive->new($state, $i, + $state->opt('y')); } - $state->{interactive} //= OpenBSD::InteractiveStub->new($state); + $state->{interactive} //= OpenBSD::InteractiveStub->new($state, + $state->opt('y')); } @@ -209,8 +211,11 @@ sub try_and_run_command package OpenBSD::InteractiveStub; sub new { - my $class = shift; - bless {}, $class; + my ($class, $state, $always) = @_; + bless { + state => $state, + always => $always, + }, $class; } sub ask_list @@ -222,6 +227,9 @@ sub ask_list sub confirm { my ($self, $prompt, $yesno) = @_; + if ($self->{always}) { + return 1; + } return $yesno; } Index: OpenBSD/AddDelete.pm =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/AddDelete.pm,v retrieving revision 1.93 diff -u -p -r1.93 AddDelete.pm --- OpenBSD/AddDelete.pm 11 Jan 2020 13:46:39 -0000 1.93 +++ OpenBSD/AddDelete.pm 27 Nov 2020 06:38:45 -0000 @@ -231,7 +231,7 @@ sub handle_options }; $state->{no_exports} = 1; $state->add_interactive_options; - $state->SUPER::handle_options($opt_string.'aciInqsVB:', @usage); + $state->SUPER::handle_options($opt_string.'aciInqsyVB:', @usage); if ($state->opt('s')) { $state->{not} = 1; Index: OpenBSD/FwUpdate.pm =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/FwUpdate.pm,v retrieving revision 1.32 diff -u -p -r1.32 FwUpdate.pm --- OpenBSD/FwUpdate.pm 11 Feb 2020 16:20:05 -0000 1.32 +++ OpenBSD/FwUpdate.pm 27 Nov 2020 06:38:45 -0000 @@ -67,7 +67,7 @@ sub handle_options $state->{localbase} = OpenBSD::Paths->localbase; $state->{destdir} = ''; $state->{wantntogo} = 0; - $state->{interactive} = OpenBSD::InteractiveStub->new($state); + $state->{interactive} = OpenBSD::InteractiveStub->new($state, 0); $state->{subst}->add('repair', 1); if ($state->opt('a') && @ARGV != 0) { $state->usage; Index: OpenBSD/Interactive.pm =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/Interactive.pm,v retrieving revision 1.22 diff -u -p -r1.22 Interactive.pm --- OpenBSD/Interactive.pm 26 Feb 2018 13:53:31 -0000 1.22 +++ OpenBSD/Interactive.pm 27 Nov 2020 06:38:45 -0000 @@ -21,10 +21,10 @@ package OpenBSD::Interactive; sub new { - my ($class, $state, $level) = @_; + my ($class, $state, $level, $always) = @_; bless { state => $state, - always => 0, + always => $always, level => $level, }, $class; } Index: OpenBSD/PkgAdd.pm =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm,v retrieving revision 1.118 diff -u -p -r1.118 PkgAdd.pm --- OpenBSD/PkgAdd.pm 8 Dec 2019 10:35:17 -0000 1.118 +++ OpenBSD/PkgAdd.pm 27 Nov 2020 06:38:45 -0000 @@ -113,7 +113,7 @@ sub handle_options { my $state = shift; $state->SUPER::handle_options('druUzl:A:P:', - '[-adcinqrsUuVvxz] [-A arch] [-B pkg-destdir] [-D name[=value]]', + '[-adcinqrsUuVvxyz] [-A arch] [-B pkg-destdir] [-D name[=value]]', '[-L localbase] [-l file] [-P type] pkg-name ...'); $state->{arch} = $state->opt('A'); Index: OpenBSD/PkgDelete.pm =================================================================== RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm,v retrieving revision 1.47 diff -u -p -r1.47 PkgDelete.pm --- OpenBSD/PkgDelete.pm 9 Jun 2019 09:36:24 -0000 1.47 +++ OpenBSD/PkgDelete.pm 27 Nov 2020 06:38:45 -0000 @@ -101,7 +101,7 @@ sub handle_options { my $state = shift; $state->SUPER::handle_options('X', - '[-acimnqsVvXx] [-B pkg-destdir] [-D name[=value]] [pkg-name ...]'); + '[-acimnqsVvXxy] [-B pkg-destdir] [-D name[=value]] [pkg-name ...]'); $state->{exclude} = $state->opt('X'); }