about summary refs log tree commit homepage
path: root/lib/PublicInbox/Admin.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-05-28 23:48:52 +0000
committerEric Wong <e@80x24.org>2019-05-29 08:05:47 +0000
commitde1a674545481c779bc49feef028eacc1e181d5d (patch)
tree4beb336b63bf7c69db3ca4285824002866ae36ba /lib/PublicInbox/Admin.pm
parentbc76942dee09114695b276b45dd9221cd651defb (diff)
downloadpublic-inbox-de1a674545481c779bc49feef028eacc1e181d5d.tar.gz
It doesn't implement progress of batches, yet, but it wires
up the parsing of the command-line while preserving output
compatibility.

This output is NOT meant to be stable.
Diffstat (limited to 'lib/PublicInbox/Admin.pm')
-rw-r--r--lib/PublicInbox/Admin.pm18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm
index 34aa3129..07d8b572 100644
--- a/lib/PublicInbox/Admin.pm
+++ b/lib/PublicInbox/Admin.pm
@@ -167,4 +167,22 @@ sub index_inbox {
         }
 }
 
+sub progress_prepare ($) {
+        my ($opt) = @_;
+
+        # public-inbox-index defaults to quiet, -xcpdb and -compact do not
+        if (defined($opt->{quiet}) && $opt->{quiet} < 0) {
+                $opt->{quiet} = !$opt->{verbose};
+        }
+        if ($opt->{quiet}) {
+                open my $null, '>', '/dev/null' or
+                        die "failed to open /dev/null: $!\n";
+                $opt->{1} = fileno($null); # suitable for spawn() redirect
+                $opt->{-dev_null} = $null;
+        } else {
+                $opt->{verbose} ||= 1;
+                $opt->{-progress} = sub { print STDERR @_ };
+        }
+}
+
 1;