]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei forget-search: new command to forget saved searches
authorEric Wong <e@80x24.org>
Tue, 20 Apr 2021 07:16:54 +0000 (07:16 +0000)
committerEric Wong <e@80x24.org>
Tue, 20 Apr 2021 19:02:48 +0000 (19:02 +0000)
Readers may lose interest in subscription topics.  This lets
them avoid clutter by forgetting a saved search.

This does not and will not destroy the contents of an --output
mailbox.  In other words, this is similar to unsubscribing
from an Atom/RSS feed or NNTP group.

I've also decided we won't support 'mv-search', since it'll
probably be rarely used and "lei convert" can be used, instead.

MANIFEST
lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiForgetSearch.pm [new file with mode: 0644]
t/lei-q-save.t

index f4a5568755f7d3fda9f5166ecc1573052d54767e..2b73387ba3927a3cf03b8ffa300fddc89b7acbf3 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -191,6 +191,7 @@ lib/PublicInbox/LeiConvert.pm
 lib/PublicInbox/LeiCurl.pm
 lib/PublicInbox/LeiDedupe.pm
 lib/PublicInbox/LeiExternal.pm
+lib/PublicInbox/LeiForgetSearch.pm
 lib/PublicInbox/LeiHelp.pm
 lib/PublicInbox/LeiImport.pm
 lib/PublicInbox/LeiInit.pm
index c0385eb59320d7177b2f9c2284bc8dd7cd6d05f0..c3c796315b07beb125140d00afeb4f668a1e27ee 100644 (file)
@@ -160,8 +160,8 @@ our %CMD = ( # sorted in order of importance/use:
 
 'ls-search' => [ '[PREFIX]', 'list saved search queries',
                qw(format|f=s pretty l ascii z|0), @c_opt ],
-'rm-query' => [ 'QUERY_NAME', 'remove a saved search', @c_opt ],
-'mv-query' => [ qw(OLD_NAME NEW_NAME), 'rename a saved search', @c_opt ],
+'forget-search' => [ 'OUTPUT', 'forget a saved search',
+               qw(verbose|v+), @c_opt ],
 
 'plonk' => [ '--threads|--from=IDENT',
        'exclude mail matching From: or threads from non-Message-ID searches',
diff --git a/lib/PublicInbox/LeiForgetSearch.pm b/lib/PublicInbox/LeiForgetSearch.pm
new file mode 100644 (file)
index 0000000..b5fe5fb
--- /dev/null
@@ -0,0 +1,32 @@
+# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# "lei forget-search" forget/remove a saved search "lei q --save"
+package PublicInbox::LeiForgetSearch;
+use strict;
+use v5.10.1;
+use PublicInbox::LeiSavedSearch;
+use PublicInbox::LeiUp;
+use File::Path ();
+use SelectSaver;
+
+sub lei_forget_search {
+       my ($lei, $out) = @_;
+       my $d = PublicInbox::LeiSavedSearch::lss_dir_for($lei, \$out);
+       if (-e $d) {
+               my $save;
+               my $opt = { safe => 1 };
+               if ($lei->{opt}->{verbose}) {
+                       $opt->{verbose} = 1;
+                       $save = SelectSaver->new($lei->{2});
+               }
+               File::Path::remove_tree($d, $opt);
+       } else {
+               $lei->fail("--save was not used with $out cwd=".
+                                       $lei->rel2abs('.'));
+       }
+}
+
+*_complete_forget_search = \&PublicInbox::LeiUp::_complete_up;
+
+1;
index 5834217113e5ed1c1291d61da0c5b8c7121c3050..5a2f7fff5f54612c2c177b3746bb31ba1338ba13 100644 (file)
@@ -110,5 +110,16 @@ test_lei(sub {
        like($mb, qr/<qp\@example\.com>/, 'new result written w/ -a');
 
        lei_ok(qw(up --all=local));
+
+       ok(!lei(qw(forget-search), "$home/bogus"), 'bogus forget');
+       lei_ok qw(_complete lei forget-search);
+       like($lei_out, qr/mbrd-aug/, 'forget-search completion');
+       lei_ok(qw(forget-search -v), "$home/mbrd-aug");
+       is($lei_out, '', 'no output');
+       like($lei_err, qr/\bmbrd-aug\b/, '-v (verbose) reported unlinks');
+       lei_ok qw(_complete lei forget-search);
+       unlike($lei_out, qr/mbrd-aug/,
+               'forget-search completion cleared after forget');
+       ok(!lei('up', "$home/mbrd-aug"), 'lei up fails after forget');
 });
 done_testing;