about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiRmWatch.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox/LeiRmWatch.pm')
-rw-r--r--lib/PublicInbox/LeiRmWatch.pm31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/PublicInbox/LeiRmWatch.pm b/lib/PublicInbox/LeiRmWatch.pm
new file mode 100644
index 00000000..19bee3ab
--- /dev/null
+++ b/lib/PublicInbox/LeiRmWatch.pm
@@ -0,0 +1,31 @@
+# Copyright all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# "lei rm-watch" command
+package PublicInbox::LeiRmWatch;
+use strict;
+use v5.10.1;
+use parent qw(PublicInbox::LeiInput);
+
+sub lei_rm_watch {
+        my ($lei, @argv) = @_;
+        my $cfg = $lei->_lei_cfg(1);
+        $lei->{opt}->{'mail-sync'} = 1; # for prepare_inputs
+        my $self = bless { missing_ok => 1 }, __PACKAGE__;
+        $self->prepare_inputs($lei, \@argv) or return;
+        for my $w (@{$self->{inputs}}) {
+                $lei->_config('--remove-section', "watch.$w") or return;
+        }
+        delete $lei->{cfg}; # force reload
+        $lei->refresh_watches;
+}
+
+sub _complete_rm_watch {
+        my ($lei, @argv) = @_;
+        my $cfg = $lei->_lei_cfg or return;
+        my $match_cb = $lei->complete_url_prepare(\@argv);
+        my @w = (join("\n", keys %$cfg) =~ m/^watch\.(.+?)\.state$/sgm);
+        map { $match_cb->($_) } @w;
+}
+
+1;