about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiExternal.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-02-06 12:18:42 +0000
committerEric Wong <e@80x24.org>2021-02-07 03:34:32 +0000
commite591a7bfdd57884f187afbf2229f2834639a4489 (patch)
treef6800ab602dd51b51a0c653eadef4525cd70a271 /lib/PublicInbox/LeiExternal.pm
parent5234287546c10ab543f83431da0dc2f2d8ce6d4e (diff)
downloadpublic-inbox-e591a7bfdd57884f187afbf2229f2834639a4489.tar.gz
Option combinations which make no sense should fail
to prevent misunderstandings and avoid surprises.
Diffstat (limited to 'lib/PublicInbox/LeiExternal.pm')
-rw-r--r--lib/PublicInbox/LeiExternal.pm22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm
index 6a5c2517..b65dc87c 100644
--- a/lib/PublicInbox/LeiExternal.pm
+++ b/lib/PublicInbox/LeiExternal.pm
@@ -101,9 +101,27 @@ sub add_external_finish {
 sub lei_add_external {
         my ($self, $location) = @_;
         $self->_lei_store(1)->write_prepare($self);
-        my $new_boost = $self->{opt}->{boost} // 0;
+        my $opt = $self->{opt};
+        my $mirror = $opt->{mirror} // do {
+                my @fail;
+                for my $sw ($self->index_opt, $self->curl_opt,
+                                qw(c no-torsocks torsocks inbox-version)) {
+                        my ($f) = (split(/|/, $sw, 2))[0];
+                        next unless defined $opt->{$f};
+                        $f = length($f) == 1 ? "-$f" : "--$f";
+                        push @fail, $f;
+                }
+                if (scalar(@fail) == 1) {
+                        return $self->("@fail requires --mirror");
+                } elsif (@fail) {
+                        my $last = pop @fail;
+                        my $fail = join(', ', @fail);
+                        return $self->("@fail and $last require --mirror");
+                }
+                undef;
+        };
+        my $new_boost = $opt->{boost} // 0;
         $location = ext_canonicalize($location);
-        my $mirror = $self->{opt}->{mirror};
         if (defined($mirror) && -d $location) {
                 $self->fail(<<""); # TODO: did you mean "update-external?"
 --mirror destination `$location' already exists