From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] lei forget-search: support multiple args
Date: Fri, 15 Oct 2021 14:02:15 +0000 [thread overview]
Message-ID: <20211015140215.2127-1-e@80x24.org> (raw)
I've been testing a lot of searches which I don't want to keep
around, so make it easy to remove a bunch at once. We'll behave
like rm(1) and keep going in the face of failure.
---
lib/PublicInbox/LEI.pm | 2 +-
lib/PublicInbox/LeiForgetSearch.pm | 30 ++++++++++++++++++------------
2 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 83534878..7dfd3398 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -225,7 +225,7 @@ 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 ],
-'forget-search' => [ 'OUTPUT', 'forget a saved search',
+'forget-search' => [ 'OUTPUT...', 'forget a saved search',
qw(verbose|v+), @c_opt ],
'edit-search' => [ 'OUTPUT', "edit saved search via `git config --edit'",
@c_opt ],
diff --git a/lib/PublicInbox/LeiForgetSearch.pm b/lib/PublicInbox/LeiForgetSearch.pm
index 717fa5e9..0db9c75b 100644
--- a/lib/PublicInbox/LeiForgetSearch.pm
+++ b/lib/PublicInbox/LeiForgetSearch.pm
@@ -11,20 +11,26 @@ use File::Path ();
use SelectSaver;
sub lei_forget_search {
- my ($lei, $out) = @_;
- my $d = PublicInbox::LeiSavedSearch::lss_dir_for($lei, \$out, 1);
- if (-e $d) {
- my $save;
- my $opt = { safe => 1 };
- if ($lei->{opt}->{verbose}) {
- $opt->{verbose} = 1;
- $save = SelectSaver->new($lei->{2});
+ my ($lei, @outs) = @_;
+ my @dirs; # paths in ~/.local/share/lei/saved-search/
+ my $cwd;
+ for my $o (@outs) {
+ my $d = PublicInbox::LeiSavedSearch::lss_dir_for($lei, \$o, 1);
+ if (-e $d) {
+ push @dirs, $d
+ } else { # keep going, like rm(1):
+ $cwd //= $lei->rel2abs('.');
+ warn "--save was not used with $o cwd=$cwd\n";
}
- File::Path::remove_tree($d, $opt);
- } else {
- $lei->fail("--save was not used with $out cwd=".
- $lei->rel2abs('.'));
}
+ my $save;
+ my $opt = { safe => 1 };
+ if ($lei->{opt}->{verbose}) {
+ $opt->{verbose} = 1;
+ $save = SelectSaver->new($lei->{2});
+ }
+ File::Path::remove_tree(@dirs, $opt);
+ $lei->fail if defined $cwd;
}
*_complete_forget_search = \&PublicInbox::LeiUp::_complete_up;
reply other threads:[~2021-10-15 14:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211015140215.2127-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).