]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiRmWatch.pm
imap+nntp: share COMPRESS implementation
[public-inbox.git] / lib / PublicInbox / LeiRmWatch.pm
1 # Copyright all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # "lei rm-watch" command
5 package PublicInbox::LeiRmWatch;
6 use strict;
7 use v5.10.1;
8 use parent qw(PublicInbox::LeiInput);
9
10 sub lei_rm_watch {
11         my ($lei, @argv) = @_;
12         my $cfg = $lei->_lei_cfg(1);
13         $lei->{opt}->{'mail-sync'} = 1; # for prepare_inputs
14         my $self = bless { missing_ok => 1 }, __PACKAGE__;
15         $self->prepare_inputs($lei, \@argv) or return;
16         for my $w (@{$self->{inputs}}) {
17                 $lei->_config('--remove-section', "watch.$w");
18         }
19         delete $lei->{cfg}; # force reload
20         $lei->refresh_watches;
21 }
22
23 sub _complete_rm_watch {
24         my ($lei, @argv) = @_;
25         my $cfg = $lei->_lei_cfg or return;
26         my $match_cb = $lei->complete_url_prepare(\@argv);
27         my @w = (join("\n", keys %$cfg) =~ m/^watch\.(.+?)\.state$/sgm);
28         map { $match_cb->($_) } @w;
29 }
30
31 1;