This will be useful, later.
lib/PublicInbox/LeiInspect.pm
lib/PublicInbox/LeiLsLabel.pm
lib/PublicInbox/LeiLsSearch.pm
+lib/PublicInbox/LeiLsSync.pm
lib/PublicInbox/LeiMailSync.pm
lib/PublicInbox/LeiMirror.pm
lib/PublicInbox/LeiOverview.pm
'ls-external' => [ '[FILTER]', 'list publicinbox|extindex locations',
qw(format|f=s z|0 globoff|g invert-match|v local remote), @c_opt ],
'ls-label' => [ '', 'list labels', qw(z|0 stats:s), @c_opt ],
+'ls-sync' => [ '', 'list sync folders',
+ qw(z|0 z|0 globoff|g invert-match|v local remote), @c_opt ],
'forget-external' => [ 'LOCATION...|--prune',
'exclude further results from a publicinbox|extindex',
qw(prune), @c_opt ],
'[' => '[', ']' => ']', ',' => ',' );
sub glob2re {
- my ($re) = @_;
+ my $re = $_[-1];
my $p = '';
my $in_bracket = 0;
my $qm = 0;
--- /dev/null
+# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# front-end for the "lei ls-sync" sub-command
+package PublicInbox::LeiLsSync;
+use strict;
+use v5.10.1;
+use PublicInbox::LeiMailSync;
+
+sub lei_ls_sync {
+ my ($lei, $filter) = @_;
+ my $sto = $lei->_lei_store or return;
+ my $lms = $sto->search->lms or return;
+ my $opt = $lei->{opt};
+ my $re;
+ $re = defined($filter) ? qr/\Q$filter\E/ : qr/./ if $opt->{globoff};
+ $re //= $lei->glob2re($filter // '*');
+ my @f = $lms->folders;
+ @f = $opt->{'invert-match'} ? grep(!/$re/, @f) : grep(/$re/, @f);
+ if ($opt->{'local'} && !$opt->{remote}) {
+ @f = grep(!m!\A[a-z\+]+://!i, @f);
+ } elsif ($opt->{remote} && !$opt->{'local'}) {
+ @f = grep(m!\A[a-z\+]+://!i, @f);
+ }
+ my $ORS = $opt->{z} ? "\0" : "\n";
+ $lei->out(join($ORS, @f, ''));
+}
+
+1;
is_deeply(json_utf8->decode($lei_out), {}, 'no inspect stats, yet');
lei_ok('import', $url);
+ lei_ok 'ls-sync';
+ like($lei_out, qr!\A\Q$url\E;UIDVALIDITY=\d+\n\z!, 'ls-sync');
lei_ok('inspect', $url);
my $inspect = json_utf8->decode($lei_out);
is_deeply($inspect, { sync => { "maildir:$md" => [ 'x:2,S' ] } },
'maildir sync info as expected');
+ lei_ok qw(ls-sync);
+ is($lei_out, "maildir:$md\n", 'ls-sync as expected');
+
lei_ok(qw(import), $md, \'import Maildir again');
$imp_err = $lei_err;
lei_ok(qw(q -d none s:boolean), \'lei q w/o dedupe');