]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LEI.pm
lei up: support --all for IMAP folders
[public-inbox.git] / lib / PublicInbox / LEI.pm
index 9e9aa165acc1f689bac09b69b5ac93068f647659..a258722e04d582724e567011aabd6c321e16c3a7 100644 (file)
@@ -279,8 +279,8 @@ our %CMD = ( # sorted in order of importance/use:
                'git-config(1) wrapper for '._config_path($_[0]);
        }, qw(config-file|system|global|file|f=s), # for conflict detection
         qw(c=s@ C=s@), pass_through('git config') ],
-'inspect' => [ 'ITEMS...', 'inspect lei/store and/or local external',
-       qw(pretty ascii dir=s), @c_opt ],
+'inspect' => [ 'ITEMS...|--stdin', 'inspect lei/store and/or local external',
+       qw(stdin| pretty ascii dir=s), @c_opt ],
 
 'init' => [ '[DIRNAME]', sub {
        "initialize storage, default: ".store_path($_[0]);
@@ -532,6 +532,7 @@ sub puts ($;@) { out(shift, map { "$_\n" } @_) }
 
 sub child_error { # passes non-fatal curl exit codes to user
        my ($self, $child_error, $msg) = @_; # child_error is $?
+       $child_error ||= 1 << 8;
        $self->err($msg) if $msg;
        if ($self->{pkt_op_p}) { # to top lei-daemon
                $self->{pkt_op_p}->pkt_do('child_error', $child_error);
@@ -604,16 +605,19 @@ sub incr {
        $self->{counters}->{$field} += $nr;
 }
 
+sub pkt_ops {
+       my ($lei, $ops) = @_;
+       $ops->{'!'} = [ \&fail_handler, $lei ];
+       $ops->{'|'} = [ \&sigpipe_handler, $lei ];
+       $ops->{x_it} = [ \&x_it, $lei ];
+       $ops->{child_error} = [ \&child_error, $lei ];
+       $ops->{incr} = [ \&incr, $lei ];
+       $ops;
+}
+
 sub workers_start {
        my ($lei, $wq, $jobs, $ops, $flds) = @_;
-       $ops = {
-               '!' => [ \&fail_handler, $lei ],
-               '|' => [ \&sigpipe_handler, $lei ],
-               'x_it' => [ \&x_it, $lei ],
-               'child_error' => [ \&child_error, $lei ],
-               'incr' => [ \&incr, $lei ],
-               ($ops ? %$ops : ()),
-       };
+       $ops = pkt_ops($lei, { ($ops ? %$ops : ()) });
        $ops->{''} //= [ $wq->can('_lei_wq_eof') || \&wq_eof, $lei ];
        my $end = $lei->pkt_op_pair;
        my $ident = $wq->{-wq_ident} // "lei-$lei->{cmd} worker";
@@ -1329,6 +1333,7 @@ sub lazy_start {
        open STDOUT, '>&STDIN' or die "redirect stdout failed: $!";
        # $daemon pipe to `lei' closed, main loop begins:
        PublicInbox::DS->EventLoop;
+       dump_and_clear_log();
        exit($exit_code // 0);
 }
 
@@ -1341,7 +1346,7 @@ sub DESTROY {
        if (my $counters = delete $self->{counters}) {
                for my $k (sort keys %$counters) {
                        my $nr = $counters->{$k};
-                       $self->child_error(1 << 8, "$nr $k messages");
+                       $self->child_error(0, "$nr $k messages");
                }
        }
        $self->{1}->autoflush(1) if $self->{1};
@@ -1417,7 +1422,7 @@ sub refresh_watches {
                                add_maildir_watch($d, $cfg_f);
                        }
                } else { # TODO: imap/nntp/jmap
-                       $lei->child_error(1, "E: watch $url not supported, yet")
+                       $lei->child_error(0, "E: watch $url not supported, yet")
                }
        }
 
@@ -1452,7 +1457,7 @@ sub refresh_watches {
                                my $d = canonpath_harder($1);
                                cancel_maildir_watch($d, $cfg_f);
                        } else { # TODO: imap/nntp/jmap
-                               $lei->child_error(1, "E: watch $url TODO");
+                               $lei->child_error(0, "E: watch $url TODO");
                        }
                }
        }