]> Sergey Matveev's repositories - public-inbox.git/commitdiff
index: support --verbose option
authorEric Wong <e@80x24.org>
Tue, 28 May 2019 23:48:52 +0000 (23:48 +0000)
committerEric Wong <e@80x24.org>
Wed, 29 May 2019 08:05:47 +0000 (08:05 +0000)
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.

lib/PublicInbox/Admin.pm
lib/PublicInbox/Xapcmd.pm
script/public-inbox-index

index 34aa3129f5228de6166f7b5d84261cdea0631e8a..07d8b572c3d3075e9f7ef94620ca19d3096bc2a7 100644 (file)
@@ -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;
index 999819c74b6ccb52eac4de475b2a74a318efad89..7e3d47fb9b26240e4fc563afcbf01ccb61b61b60 100644 (file)
@@ -86,18 +86,6 @@ sub prepare_reindex ($$) {
        }
 }
 
-sub progress_prepare ($) {
-       my ($opt) = @_;
-       if ($opt->{quiet}) {
-               open my $null, '>', '/dev/null' or
-                       die "failed to open /dev/null: $!\n";
-               $opt->{1} = fileno($null);
-               $opt->{-dev_null} = $null;
-       } else {
-               $opt->{-progress} = sub { print STDERR @_ };
-       }
-}
-
 sub same_fs_or_die ($$) {
        my ($x, $y) = @_;
        return if ((stat($x))[0] == (stat($y))[0]); # 0 - st_dev
@@ -132,7 +120,7 @@ sub process_queue {
 sub run {
        my ($ibx, $task, $opt) = @_; # task = 'cpdb' or 'compact'
        my $cb = \&${\"PublicInbox::Xapcmd::$task"};
-       progress_prepare($opt ||= {});
+       PublicInbox::Admin::progress_prepare($opt ||= {});
        my $dir = $ibx->{mainrepo} or die "no mainrepo in inbox\n";
        runnable_or_die($XAPIAN_COMPACT) if $opt->{compact};
        my $reindex; # v1:{ from => $x40 }, v2:{ from => [ $x40, $x40, .. ] } }
index 40187b35018f84d6cd86e18959455ce877be365f..c0d637b109d886ecdd2c89424bf1cb488d3aa8d1 100755 (executable)
@@ -13,8 +13,8 @@ my $usage = "public-inbox-index INBOX_DIR";
 use PublicInbox::Admin;
 PublicInbox::Admin::require_or_die('-index');
 
-my $opt = {};
-GetOptions($opt, qw(reindex jobs|j=i prune indexlevel|L=s))
+my $opt = { quiet => -1 };
+GetOptions($opt, qw(verbose|v+ reindex jobs|j=i prune indexlevel|L=s))
        or die "bad command-line args\n$usage";
 die "--jobs must be positive\n" if defined $opt->{jobs} && $opt->{jobs} <= 0;
 
@@ -35,4 +35,5 @@ foreach my $ibx (@ibxs) {
 }
 
 PublicInbox::Admin::require_or_die(keys %$mods);
+PublicInbox::Admin::progress_prepare($opt);
 PublicInbox::Admin::index_inbox($_, $opt) for @ibxs;