user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] lei forget-search: support multiple args
@ 2021-10-15 14:02 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-10-15 14:02 UTC (permalink / raw)
  To: meta

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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-15 14:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15 14:02 [PATCH] lei forget-search: support multiple args Eric Wong

Code repositories for project(s) associated with this 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).