]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiLsSync.pm
lei_saved_search: fix excess indent for first lei.q entry
[public-inbox.git] / lib / PublicInbox / LeiLsSync.pm
1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # front-end for the "lei ls-sync" sub-command
5 package PublicInbox::LeiLsSync;
6 use strict;
7 use v5.10.1;
8 use PublicInbox::LeiMailSync;
9
10 sub lei_ls_sync {
11         my ($lei, $filter) = @_;
12         my $sto = $lei->_lei_store or return;
13         my $lms = $sto->search->lms or return;
14         my $opt = $lei->{opt};
15         my $re;
16         $re = defined($filter) ? qr/\Q$filter\E/ : qr/./ if $opt->{globoff};
17         $re //= $lei->glob2re($filter // '*');
18         my @f = $lms->folders;
19         @f = $opt->{'invert-match'} ? grep(!/$re/, @f) : grep(/$re/, @f);
20         if ($opt->{'local'} && !$opt->{remote}) {
21                 @f = grep(!m!\A[a-z\+]+://!i, @f);
22         } elsif ($opt->{remote} && !$opt->{'local'}) {
23                 @f = grep(m!\A[a-z\+]+://!i, @f);
24         }
25         my $ORS = $opt->{z} ? "\0" : "\n";
26         $lei->out(join($ORS, @f, ''));
27 }
28
29 1;