From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] lei q: -I/--include overrides --no-(external|local|remote)
Date: Fri, 19 Mar 2021 20:38:49 -0200 [thread overview]
Message-ID: <20210319223849.26185-1-e@80x24.org> (raw)
Assume that anybody using -I/--include for external locations
will want to override --no-$FOO if they're explicitly including
a location.
With some effort, we could make it order-dependent (e.g.
"-I $LOCATION --no-$FOO" and "--no-$FOO -I $LOCATION"
behave differently). However that's not straightforward
when using Getopt::Long to parse command-line options into
a hashref.
I'm also not sure if order-dependent switches are a desirable
UI/UX quality.
---
lib/PublicInbox/LeiQuery.pm | 7 +++++--
t/lei-externals.t | 15 +++++++++++++--
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm
index 623b92cd..532668ae 100644
--- a/lib/PublicInbox/LeiQuery.pm
+++ b/lib/PublicInbox/LeiQuery.pm
@@ -64,9 +64,12 @@ sub lei_q {
$lxs->prepare_external($_) for @loc;
}
} else {
+ my (@ilocals, @iremotes);
for my $loc (@{$opt->{include} // []}) {
my @loc = $self->get_externals($loc) or return;
$lxs->prepare_external($_) for @loc;
+ @ilocals = @{$lxs->{locals} // []};
+ @iremotes = @{$lxs->{remotes} // []};
}
# --external is enabled by default, but allow --no-external
if ($opt->{external} //= 1) {
@@ -78,9 +81,9 @@ sub lei_q {
my $ne = $self->externals_each(\&prep_ext, $lxs, \%x);
$opt->{remote} //= !($lxs->locals - $opt->{'local'});
if ($opt->{'local'}) {
- delete($lxs->{remotes}) if !$opt->{remote};
+ $lxs->{remotes} = \@iremotes if !$opt->{remote};
} else {
- delete($lxs->{locals});
+ $lxs->{locals} = \@ilocals;
}
}
}
diff --git a/t/lei-externals.t b/t/lei-externals.t
index 1695ff0b..1d2a9a16 100644
--- a/t/lei-externals.t
+++ b/t/lei-externals.t
@@ -127,8 +127,10 @@ test_lei(sub {
lei_ok qw(_complete lei forget-external), \'complete for externals';
my %comp = map { $_ => 1 } split(/\s+/, $lei_out);
ok($comp{'https://example.com/ibx/'}, 'forget external completion');
+ my @dirs;
$cfg->each_inbox(sub {
my ($ibx) = @_;
+ push @dirs, $ibx->{inboxdir};
ok($comp{$ibx->{inboxdir}}, "local $ibx->{name} completion");
});
for my $u (qw(h http https https: https:/ https:// https://e
@@ -157,7 +159,8 @@ test_lei(sub {
lei_ok('ls-external');
unlike($lei_out, qr!https://example\.com/ibx/!s,
'removed canonical URL');
-SKIP: {
+
+ # do some queries
ok(!lei(qw(q s:prefix -o maildir:/dev/null)), 'bad maildir');
like($lei_err, qr!/dev/null exists and is not a directory!,
'error shown');
@@ -249,6 +252,15 @@ SKIP: {
is($? >> 8, 1, 'proper exit code');
like($lei_err, qr/no local or remote.+? to search/, 'no inbox');
+ for my $no (['--no-local'], ['--no-external'],
+ [qw(--no-local --no-external)]) {
+ lei_ok(qw(q mid:testmessage@example.com), @$no,
+ '-I', $dirs[0], \"-I and @$no combine");
+ $res = json_utf8->decode($lei_out);
+ is($res->[0]->{'m'}, 'testmessage@example.com',
+ "-I \$DIR got results regardless of @$no");
+ }
+
{
opendir my $dh, '.' or BAIL_OUT "opendir(.) $!";
my $od = PublicInbox::OnDestroy->new($$, sub {
@@ -278,6 +290,5 @@ SKIP: {
$url = $e{$k} if $url eq '1';
$test_external_remote->($url, $k);
}
- }; # /SKIP
}); # test_lei
done_testing;
reply other threads:[~2021-03-19 22:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210319223849.26185-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).