-my $usage = "public-inbox-index REPO_DIR";
-use PublicInbox::Config;
-use PublicInbox::Admin qw(resolve_repo_dir);
-
-my $config = eval { PublicInbox::Config->new } || eval {
- warn "public-inbox unconfigured for serving, indexing anyways...\n";
- undef;
-};
-eval { require PublicInbox::SearchIdx };
-if ($@) {
- print STDERR "Search::Xapian required for $0\n";
- exit 1;
-}
-
-my $reindex;
-my $prune;
-my $jobs = undef;
-my $indexlevel;
-my %opts = (
- '--reindex' => \$reindex,
- '--jobs|j=i' => \$jobs,
- '--prune' => \$prune,
- 'L|indexlevel=s' => \$indexlevel,
-);
-GetOptions(%opts) or die "bad command-line args\n$usage";
-die "--jobs must be positive\n" if defined $jobs && $jobs < 0;
-
-my @dirs;
-
-if (@ARGV) {
- @dirs = map { resolve_repo_dir($_) } @ARGV;
-} else {
- @dirs = (resolve_repo_dir());
+my $usage = "public-inbox-index INBOX_DIR";
+use PublicInbox::Admin;
+PublicInbox::Admin::require_or_die('-index');
+use PublicInbox::Xapcmd;
+
+my $compact_opt;
+my $opt = { quiet => -1, compact => 0 };
+GetOptions($opt, qw(verbose|v+ reindex compact|c+ 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;
+
+if ($opt->{compact}) {
+ require PublicInbox::Xapcmd;
+ PublicInbox::Xapcmd::check_compact();
+ $compact_opt = { -coarse_lock => 1, compact => 1 };