package PublicInbox::LEI;
use strict;
use v5.10.1;
-use parent qw(PublicInbox::DS PublicInbox::LeiExternal);
+use parent qw(PublicInbox::DS PublicInbox::LeiExternal
+ PublicInbox::LeiQuery);
use Getopt::Long ();
use Socket qw(AF_UNIX SOCK_STREAM pack_sockaddr_un);
use Errno qw(EAGAIN ECONNREFUSED ENOENT);
our %CMD = ( # sorted in order of importance/use:
'q' => [ 'SEARCH_TERMS...', 'search for messages matching terms', qw(
save-as=s output|mfolder|o=s format|f=s dedupe|d=s thread|t augment|a
- sort|s=s@ reverse|r offset=i remote local! external!
+ sort|s=s reverse|r offset=i remote local! external! pretty
since|after=s until|before=s), opt_dash('limit|n=i', '[0-9]+') ],
'show' => [ 'MID|OID', 'show a given object (Message-ID or object ID)',
'daemon-kill' => [ '[-SIGNAL]', 'signal the lei-daemon',
opt_dash('signal|s=s', '[0-9]+|(?:[A-Z][A-Z0-9]+)') ],
'daemon-pid' => [ '', 'show the PID of the lei-daemon' ],
-'daemon-env' => [ '[NAME=VALUE...]', 'set, unset, or show daemon environment',
- qw(clear| unset|u=s@ z|0) ],
'help' => [ '[SUBCOMMAND]', 'show help' ],
# XXX do we need this?
'limit|n=i@' => ['NUM', 'limit on number of matches (default: 10000)' ],
'offset=i' => ['OFF', 'search result offset (default: 0)'],
-'sort|s=s@' => [ 'VAL|internaldate,date,relevance,docid',
+'sort|s=s' => [ 'VAL|received,relevance,docid',
"order of results `--output'-dependent"],
+'reverse|r' => [ 'reverse search results' ], # like sort(1)
'boost=i' => 'increase/decrease priority of results (default: 0)',
# xargs, env, use "-0", git(1) uses "-z". We support z|0 everywhere
'z|0' => 'use NUL \\0 instead of newline (CR) to delimit lines',
-# note: no "--ignore-environment" / "-i" support like env(1) since that
-# is one-shot and this is for a persistent daemon:
-'clear|' => 'clear the daemon environment',
-'unset|u=s@' => ['NAME',
- 'unset matching NAME, may be specified multiple times'],
-
'signal|s=s' => [ 'SIG', 'signal to send lei-daemon (default: TERM)' ],
); # %OPTDESC
my ($self, @argv) = @_;
}
-sub lei_query {
- my ($self, @argv) = @_;
-}
-
sub lei_mark {
my ($self, @argv) = @_;
}
kill($sig, $$) or fail($self, "kill($sig, $$): $!");
}
-sub lei_daemon_env {
- my ($self, @argv) = @_;
- my $opt = $self->{opt};
- if (defined $opt->{clear}) {
- %ENV = ();
- } elsif (my $u = $opt->{unset}) {
- delete @ENV{@$u};
- }
- if (@argv) {
- %ENV = (%ENV, map { split(/=/, $_, 2) } @argv);
- } elsif (!defined($opt->{clear}) && !$opt->{unset}) {
- my $eor = $opt->{z} ? "\0" : "\n";
- my $buf = '';
- while (my ($k, $v) = each %ENV) { $buf .= "$k=$v$eor" }
- out $self, $buf;
- }
-}
-
sub lei_help { _help($_[0]) }
# Shell completion helper. Used by lei-completion.bash and hopefully
my $rdr = { 0 => $r, 1 => $self->{1}, 2 => $self->{2} };
$self->{1} = $w;
$self->{2} = $w if -t $self->{2};
- $self->{'pager.pid'} = spawn([$pager], $env, $rdr);
+ my $pid = spawn([$pager], $env, $rdr);
+ dwaitpid($pid, undef, $self->{sock});
$env->{GIT_PAGER_IN_USE} = 'true'; # we may spawn git
}
};
my %env = map { split(/=/, $_, 2) } split(/\0/, $env);
if (chdir($env{PWD})) {
+ local %ENV = %env;
$self->{env} = \%env;
$self->{pid} = $client_pid;
eval { dispatch($self, split(/\]\0\[/, $argv)) };
}
}
+# for long-running results
+sub event_step {
+ my ($self) = @_;
+ local %ENV = %{$self->{env}};
+ eval {}; # TODO
+ if ($@) {
+ say { $self->{sock} } $@;
+ $self->close; # PublicInbox::DS::close
+ }
+}
+
sub noop {}
# lei(1) calls this when it can't connect
my @st = stat($path) or die "stat($path): $!";
my $dev_ino_expect = pack('dd', $st[0], $st[1]); # dev+ino
pipe(my ($eof_r, $eof_w)) or die "pipe: $!";
- my $oldset = PublicInbox::Sigfd::block_signals();
+ my $oldset = PublicInbox::DS::block_signals();
if ($nfd == 1) {
require IO::FDPass;
$recv_3fds = sub { map { IO::FDPass::recv($_[0]) } (0..2) };
} else {
# wake up every second to accept signals if we don't
# have signalfd or IO::KQueue:
- PublicInbox::Sigfd::sig_setmask($oldset);
+ PublicInbox::DS::sig_setmask($oldset);
PublicInbox::DS->SetLoopTimeout(1000);
}
PublicInbox::DS->SetPostLoopCallback(sub {
sub DESTROY {
my ($self) = @_;
$self->{1}->autoflush(1);
- if (my $pid = delete $self->{'pager.pid'}) {
- dwaitpid($pid, undef, $self->{sock});
- }
}
1;