]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiLsExternal.pm
No ext_urls
[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 .= '/?\\z' if defined $re;
17         $re //= index($filter, '/') < 0 ?
18                         qr!/\Q$filter\E/?\z! : # exact basename match
19                         qr/\Q$filter\E/; # grep -F semantics
20         my @ext = $lei->externals_each(my $boost = {});
21         @ext = $lei->{opt}->{'invert-match'} ? grep(!/$re/, @ext)
22                                         : grep(/$re/, @ext);
23         if ($lei->{opt}->{'local'} && !$lei->{opt}->{remote}) {
24                 @ext = grep(!m!\A[a-z\+]+://!, @ext);
25         } elsif ($lei->{opt}->{remote} && !$lei->{opt}->{'local'}) {
26                 @ext = grep(m!\A[a-z\+]+://!, @ext);
27         }
28         for my $loc (@ext) {
29                 $lei->out($loc, $OFS, 'boost=', $boost->{$loc}, $ORS);
30         }
31 }
32
33 1;