diff options
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/LEI.pm | 4 | ||||
-rw-r--r-- | lib/PublicInbox/LeiInput.pm | 8 | ||||
-rw-r--r-- | lib/PublicInbox/LeiRmWatch.pm | 31 |
3 files changed, 42 insertions, 1 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 52c551cf..191a0790 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -232,8 +232,10 @@ our %CMD = ( # sorted in order of importance/use: 'remove imported messages from IMAP, Maildirs, and MH', qw(exact! all jobs:i indexed), @c_opt ], -'add-watch' => [ 'LOCATION', 'watch for new messages and flag changes', +'add-watch' => [ 'LOCATION...', 'watch for new messages and flag changes', qw(poll-interval=s state=s recursive|r), @c_opt ], +'rm-watch' => [ 'LOCATION...', 'remove specified watch(es)', + qw(recursive|r), @c_opt ], 'ls-watch' => [ '[FILTER...]', 'list active watches with numbers and status', qw(l z|0), @c_opt ], 'pause-watch' => [ '[WATCH_NUMBER_OR_FILTER]', qw(all local remote), @c_opt ], diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm index fa330df5..88889f45 100644 --- a/lib/PublicInbox/LeiInput.pm +++ b/lib/PublicInbox/LeiInput.pm @@ -270,6 +270,10 @@ sub prepare_inputs { # returns undef on error $sync and $input = 'maildir:'. $lei->abs_path($input_path); push @md, $input; + } elsif ($self->{missing_ok} && !-e _) { + # for "lei rm-watch" on missing Maildir + $sync and $input = 'maildir:'. + $lei->abs_path($input_path); } else { return $lei->fail("Unable to handle $input"); } @@ -305,6 +309,10 @@ $input is `eml', not --in-format=$in_fmt push @{$sync->{ok}}, $input; } push @md, $input; + } elsif ($self->{missing_ok} && !-e $input) { + # for lei rm-watch + $sync and $input = 'maildir:'. + $lei->abs_path($input); } else { return $lei->fail("Unable to handle $input") } diff --git a/lib/PublicInbox/LeiRmWatch.pm b/lib/PublicInbox/LeiRmWatch.pm new file mode 100644 index 00000000..c0f336f0 --- /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"); + } + 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; |