1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # "lei ls-external" command
5 package PublicInbox::LeiLsExternal;
9 # TODO: does this need JSON output?
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");
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)
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);
29 $lei->out($loc, $OFS, 'boost=', $boost->{$loc}, $ORS);