]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiLsExternal.pm
imap+nntp: share COMPRESS implementation
[public-inbox.git] / lib / PublicInbox / LeiLsExternal.pm
1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # "lei ls-external" command
5 package PublicInbox::LeiLsExternal;
6 use strict;
7 use v5.10.1;
8
9 # TODO: does this need JSON output?
10 sub lei_ls_external {
11         my ($lei, $filter) = @_;
12         my $do_glob = !$lei->{opt}->{globoff}; # glob by default
13         my ($OFS, $ORS) = $lei->{opt}->{z} ? ("\0", "\0\0") : (" ", "\n");
14         $filter //= '*';
15         my $re = $do_glob ? $lei->glob2re($filter) : undef;
16         $re //= index($filter, '/') < 0 ?
17                         qr!/\Q$filter\E/?\z! : # exact basename match
18                         qr/\Q$filter\E/; # grep -F semantics
19         my @ext = $lei->externals_each(my $boost = {});
20         @ext = $lei->{opt}->{'invert-match'} ? grep(!/$re/, @ext)
21                                         : grep(/$re/, @ext);
22         if ($lei->{opt}->{'local'} && !$lei->{opt}->{remote}) {
23                 @ext = grep(!m!\A[a-z\+]+://!, @ext);
24         } elsif ($lei->{opt}->{remote} && !$lei->{opt}->{'local'}) {
25                 @ext = grep(m!\A[a-z\+]+://!, @ext);
26         }
27         for my $loc (@ext) {
28                 $lei->out($loc, $OFS, 'boost=', $boost->{$loc}, $ORS);
29         }
30 }
31
32 1;