* [PATCH 0/3] lei rm-watch, some error handling stuff
@ 2021-07-23 10:56 7% Eric Wong
2021-07-23 10:56 6% ` [PATCH 3/3] lei rm-watch: new command to support removing watches Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-07-23 10:56 UTC (permalink / raw)
To: meta
I'm considering making "tag-ro" the default watch state
and introducing the idea of implicit watches for all
"lei q" output directories.
Eric Wong (3):
t/lei*: check error messages on failures
lei: avoid SQLite COUNT() for dedupe
lei rm-watch: new command to support removing watches
MANIFEST | 1 +
lib/PublicInbox/LEI.pm | 4 +++-
lib/PublicInbox/LeiDedupe.pm | 5 ++---
lib/PublicInbox/LeiInput.pm | 8 ++++++++
lib/PublicInbox/LeiRmWatch.pm | 31 +++++++++++++++++++++++++++++++
lib/PublicInbox/LeiSavedSearch.pm | 8 ++++----
lib/PublicInbox/LeiToMail.pm | 4 ++--
lib/PublicInbox/LeiXSearch.pm | 2 +-
lib/PublicInbox/SharedKV.pm | 7 +++++++
t/lei-externals.t | 4 ++++
t/lei-import-http.t | 2 ++
t/lei-import-imap.t | 1 +
t/lei-mirror.t | 7 ++++++-
t/lei-p2q.t | 1 +
t/lei-q-kw.t | 1 +
t/lei-q-remote-import.t | 1 +
t/lei-q-save.t | 4 ++++
t/lei-tag.t | 8 +++++++-
t/lei-watch.t | 18 ++++++++++++++----
t/solver_git.t | 7 +++++++
20 files changed, 107 insertions(+), 17 deletions(-)
create mode 100644 lib/PublicInbox/LeiRmWatch.pm
^ permalink raw reply [relevance 7%]
* [PATCH 3/3] lei rm-watch: new command to support removing watches
2021-07-23 10:56 7% [PATCH 0/3] lei rm-watch, some error handling stuff Eric Wong
@ 2021-07-23 10:56 6% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-07-23 10:56 UTC (permalink / raw)
To: meta
Pretty trivial since it just invokes "git-config". It's mainly
intended to make shell completion easier.
---
MANIFEST | 1 +
lib/PublicInbox/LEI.pm | 4 +++-
lib/PublicInbox/LeiInput.pm | 8 ++++++++
lib/PublicInbox/LeiRmWatch.pm | 31 +++++++++++++++++++++++++++++++
t/lei-watch.t | 18 ++++++++++++++----
5 files changed, 57 insertions(+), 5 deletions(-)
create mode 100644 lib/PublicInbox/LeiRmWatch.pm
diff --git a/MANIFEST b/MANIFEST
index 1d79b7c9..a3913501 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -233,6 +233,7 @@ lib/PublicInbox/LeiQuery.pm
lib/PublicInbox/LeiRediff.pm
lib/PublicInbox/LeiRemote.pm
lib/PublicInbox/LeiRm.pm
+lib/PublicInbox/LeiRmWatch.pm
lib/PublicInbox/LeiSavedSearch.pm
lib/PublicInbox/LeiSearch.pm
lib/PublicInbox/LeiSelfSocket.pm
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;
diff --git a/t/lei-watch.t b/t/lei-watch.t
index 492f6c1d..9a3bfd80 100644
--- a/t/lei-watch.t
+++ b/t/lei-watch.t
@@ -2,7 +2,7 @@
# Copyright all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict; use v5.10.1; use PublicInbox::TestCommon;
-use File::Path qw(make_path);
+use File::Path qw(make_path remove_tree);
require_mods('lei');
my $have_fast_inotify = eval { require Linux::Inotify2 } ||
eval { require IO::KQueue };
@@ -71,9 +71,19 @@ test_lei(sub {
'inotify has Maildir watches');
}
- is(xsys(qw(git config -f), $cfg_f,
- '--remove-section', "watch.maildir:$md"),
- 0, 'unset config state');
+ lei_ok 'rm-watch', $md;
+ lei_ok 'ls-watch', \'refresh watches';
+ is($lei_out, '', 'no watches left');
+
+ lei_ok 'add-watch', $md2;
+ remove_tree($md2);
+ lei_ok 'rm-watch', "maildir:".$md2, \'with maildir: prefix';
+ lei_ok 'ls-watch', \'refresh watches';
+ is($lei_out, '', 'no watches left');
+
+ lei_ok 'add-watch', $md;
+ remove_tree($md);
+ lei_ok 'rm-watch', $md, \'absolute path w/ missing dir';
lei_ok 'ls-watch', \'refresh watches';
is($lei_out, '', 'no watches left');
^ permalink raw reply related [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-07-23 10:56 7% [PATCH 0/3] lei rm-watch, some error handling stuff Eric Wong
2021-07-23 10:56 6% ` [PATCH 3/3] lei rm-watch: new command to support removing watches Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).