about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiQuery.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-17 10:11:04 +0000
committerEric Wong <e@80x24.org>2023-10-17 20:30:05 +0000
commitcb1c4976f116ebdf94300fd474c7176e82122003 (patch)
tree405e044a4d2397acd24aedfd6f0d28bd51124a72 /lib/PublicInbox/LeiQuery.pm
parente740838a3854a45e51d8ae089a90f08c076190bd (diff)
downloadpublic-inbox-cb1c4976f116ebdf94300fd474c7176e82122003.tar.gz
We can share more code amongst stdin slurper (not streaming)
commands.  This also fixes uninitialized variable warnings when
feeding an empty stdin to these commands.
Diffstat (limited to 'lib/PublicInbox/LeiQuery.pm')
-rw-r--r--lib/PublicInbox/LeiQuery.pm14
1 files changed, 3 insertions, 11 deletions
diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm
index e2d8a096..eadf811f 100644
--- a/lib/PublicInbox/LeiQuery.pm
+++ b/lib/PublicInbox/LeiQuery.pm
@@ -61,19 +61,13 @@ sub _start_query { # used by "lei q" and "lei up"
 
 sub do_qry { # do_env cb
         my ($lei) = @_;
-        $lei->{mset_opt}->{q_raw} = $lei->{mset_opt}->{qstr};
+        $lei->{mset_opt}->{q_raw} = $lei->{mset_opt}->{qstr}
+                                                = delete $lei->{stdin_buf};
         $lei->{lse}->query_approxidate($lei->{lse}->git,
                                         $lei->{mset_opt}->{qstr});
         _start_query($lei);
 }
 
-sub qstr_add { # PublicInbox::InputPipe::consume callback for --stdin
-        my ($lei) = @_; # $_[1] = $rbuf
-        $_[1] // $lei->fail("error reading stdin: $!");
-        return $lei->{mset_opt}->{qstr} .= $_[1] if $_[1] ne '';
-        $lei->do_env(\&do_qry);
-}
-
 # make the URI||PublicInbox::{Inbox,ExtSearch} a config-file friendly string
 sub cfg_ext ($) {
         my ($x) = @_;
@@ -159,9 +153,7 @@ sub lei_q {
                 return $self->fail(<<'') if @argv;
 no query allowed on command-line with --stdin
 
-                require PublicInbox::InputPipe;
-                PublicInbox::InputPipe::consume($self->{0}, \&qstr_add, $self);
-                return;
+                return $self->slurp_stdin(\&do_qry);
         }
         chomp(@argv) and $self->qerr("# trailing `\\n' removed");
         $mset_opt{q_raw} = [ @argv ]; # copy