]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiForgetExternal.pm
imap+nntp: share COMPRESS implementation
[public-inbox.git] / lib / PublicInbox / LeiForgetExternal.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 forget-external" command
5 package PublicInbox::LeiForgetExternal;
6 use strict;
7 use v5.10.1;
8
9 sub lei_forget_external {
10         my ($lei, @locations) = @_;
11         my $cfg = $lei->_lei_cfg or
12                 return $lei->fail('no externals configured');
13         my %seen;
14         for my $loc (@locations) {
15                 for my $l ($loc, $lei->ext_canonicalize($loc)) {
16                         next if $seen{$l}++;
17                         my $key = "external.$l.boost";
18                         delete($cfg->{$key});
19                         $lei->_config('--unset', $key);
20                         if ($? == 0) {
21                                 $lei->qerr("# $l forgotten ");
22                         } elsif (($? >> 8) == 5) {
23                                 warn("# $l not found\n");
24                         } else {
25                                 $lei->child_error($?, "# --unset $key error");
26                         }
27                 }
28         }
29 }
30
31 # shell completion helper called by lei__complete
32 sub _complete_forget_external {
33         my ($lei, @argv) = @_;
34         my $cfg = $lei->_lei_cfg or return ();
35         my ($cur, $re, $match_cb) = $lei->complete_url_prepare(\@argv);
36         # FIXME: bash completion off "http:" or "https:" when the last
37         # character is a colon doesn't work properly even if we're
38         # returning "//$HTTP_HOST/$PATH_INFO/", not sure why, could
39         # be a bash issue.
40         map {
41                 $match_cb->(substr($_, length('external.')));
42         } grep(/\Aexternal\.$re\Q$cur/, @{$cfg->{-section_order}});
43 }
44
45 1;