]> Sergey Matveev's repositories - public-inbox.git/blob - script/public-inbox-compact
compact: support --help/-? and perform lazy loading
[public-inbox.git] / script / public-inbox-compact
1 #!perl -w
2 # Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use v5.10.1;
6 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
7 my $usage = 'public-inbox-compact INBOX_DIR';
8 my $opt = { compact => 1, -coarse_lock => 1 };
9 my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
10 Usage: $usage
11
12   Compact Xapian DBs in an inbox
13
14 options:
15
16   --all               index all configured inboxes
17   --jobs=NUM          control parallelization
18
19 See public-inbox-compact(1) man page for full documentation.
20 EOF
21 GetOptions($opt, qw(all help|?),
22         # compact options:
23         qw(jobs|j=i quiet|q blocksize|b=s no-full|n fuller|F),
24 ) or die "bad command-line args\n$usage\n";
25 if ($opt->{help}) { print $help; exit 0 };
26
27 require PublicInbox::Admin;
28 PublicInbox::Admin::require_or_die('-index');
29 PublicInbox::Admin::progress_prepare($opt);
30
31 require PublicInbox::InboxWritable;
32 require PublicInbox::Xapcmd;
33 my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt);
34 unless (@ibxs) { print STDERR "Usage: $usage\n"; exit 1 }
35 foreach (@ibxs) {
36         my $ibx = PublicInbox::InboxWritable->new($_);
37         PublicInbox::Xapcmd::run($ibx, 'compact', $opt);
38 }