]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiQuery.pm
lei: more eval guards for die on failure
[public-inbox.git] / lib / PublicInbox / LeiQuery.pm
index cb5ac8fb84a72a06907075c7a65c2a7d94c3aec6..ec2ece0514929660cd9139a569cbfd8bc1c3875c 100644 (file)
@@ -55,19 +55,17 @@ sub _start_query { # used by "lei q" and "lei up"
 }
 
 sub qstr_add { # PublicInbox::InputPipe::consume callback for --stdin
-       my ($self) = @_; # $_[1] = $rbuf
-       if (defined($_[1])) {
-               $_[1] eq '' and return eval {
-                       $self->fchdir or return;
-                       $self->{mset_opt}->{q_raw} = $self->{mset_opt}->{qstr};
-                       $self->{lse}->query_approxidate($self->{lse}->git,
-                                               $self->{mset_opt}->{qstr});
-                       _start_query($self);
-               };
-               $self->{mset_opt}->{qstr} .= $_[1];
-       } else {
-               $self->fail("error reading stdin: $!");
-       }
+       my ($lei) = @_; # $_[1] = $rbuf
+       $_[1] // $lei->fail("error reading stdin: $!");
+       return $lei->{mset_opt}->{qstr} .= $_[1] if $_[1] ne '';
+       eval {
+               $lei->fchdir;
+               $lei->{mset_opt}->{q_raw} = $lei->{mset_opt}->{qstr};
+               $lei->{lse}->query_approxidate($lei->{lse}->git,
+                                               $lei->{mset_opt}->{qstr});
+               _start_query($lei);
+       };
+       $lei->fail($@) if $@;
 }
 
 sub lxs_prepare {
@@ -158,11 +156,11 @@ no query allowed on command-line with --stdin
 # shell completion helper called by lei__complete
 sub _complete_q {
        my ($self, @argv) = @_;
-       my $ext = qr/\A(?:-I|(?:--(?:include|exclude|only)))\z/;
        my @cur;
+       my $cb = $self->lazy_cb(qw(forget-external _complete_));
        while (@argv) {
-               if ($argv[-1] =~ $ext) {
-                       my @c = $self->_complete_forget_external(@cur);
+               if ($argv[-1] =~ /\A(?:-I|(?:--(?:include|exclude|only)))\z/) {
+                       my @c = $cb->($self, @cur);
                        # try basename match:
                        if (scalar(@cur) == 1 && index($cur[0], '/') < 0) {
                                my $all = $self->externals_each;