From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E9A471F670 for ; Fri, 15 Oct 2021 14:02:15 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] lei forget-search: support multiple args Date: Fri, 15 Oct 2021 14:02:15 +0000 Message-Id: <20211015140215.2127-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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;