]> Sergey Matveev's repositories - public-inbox.git/commitdiff
support -C (chdir) for most non-daemon commands
authorEric Wong <e@80x24.org>
Wed, 15 Sep 2021 21:35:59 +0000 (21:35 +0000)
committerEric Wong <e@80x24.org>
Wed, 15 Sep 2021 23:14:55 +0000 (23:14 +0000)
Because make(1), git(1), tar(1) all support -C in this form, as
do our newer commands such as lei, public-inbox-{clone,fetch}.

script/public-inbox-compact
script/public-inbox-convert
script/public-inbox-edit
script/public-inbox-extindex
script/public-inbox-index
script/public-inbox-init
script/public-inbox-purge
script/public-inbox-xcpdb

index 6e34aaeb44649180fd4ee32ba9d6190aa5458b3c..80d0224bdcb060984bc973604c2aae5e4f854771 100755 (executable)
@@ -17,7 +17,7 @@ options:
 
 See public-inbox-compact(1) man page for full documentation.
 EOF
-GetOptions($opt, qw(all help|h),
+GetOptions($opt, qw(all C=s@ help|h),
        # compact options:
        qw(jobs|j=i quiet|q blocksize|b=s no-full|n fuller|F),
 ) or die $help;
@@ -25,6 +25,7 @@ if ($opt->{help}) { print $help; exit 0 };
 
 require PublicInbox::Admin;
 PublicInbox::Admin::require_or_die('-index');
+PublicInbox::Admin::do_chdir(delete $opt->{C});
 PublicInbox::Admin::progress_prepare($opt);
 
 require PublicInbox::InboxWritable;
index 01af846aa2502ac0001e156ed5fcfc4d4941a2ca..42955a482ed378bcfaea9d2f1df4909bca6a11a2 100755 (executable)
@@ -33,7 +33,7 @@ my $opt = {
        quiet => -1, compact => 0, maxsize => undef, fsync => 1,
        reindex => 1, # we always reindex
 };
-GetOptions($opt, qw(jobs|j=i index! help|h),
+GetOptions($opt, qw(jobs|j=i index! help|h C=s@),
                # index options
                qw(verbose|v+ rethread compact|c+ fsync|sync!
                indexlevel|index-level|L=s max_size|max-size=s
@@ -41,13 +41,14 @@ GetOptions($opt, qw(jobs|j=i index! help|h),
                sequential-shard|seq-shard
                )) or die $help;
 if ($opt->{help}) { print $help; exit 0 };
+require PublicInbox::Admin;
+PublicInbox::Admin::do_chdir(delete $opt->{C});
 my $old_dir = shift(@ARGV) // '';
 my $new_dir = shift(@ARGV) // '';
 die $help if (scalar(@ARGV) || $new_dir eq '' || $old_dir eq '');
 die "$new_dir exists\n" if -d $new_dir;
 die "$old_dir not a directory\n" unless -d $old_dir;
 
-require PublicInbox::Admin;
 require PublicInbox::Config;
 require PublicInbox::InboxWritable;
 
@@ -62,7 +63,6 @@ if (delete $old->{-unconfigured}) {
 }
 die "Only conversion from v1 inboxes is supported\n" if $old->version >= 2;
 
-require PublicInbox::Admin;
 my $detected = PublicInbox::Admin::detect_indexlevel($old);
 $old->{indexlevel} //= $detected;
 my $env;
index 9498038b29e4df2c020eef94446e857905f04f8e..1fbaf5a7d11c19e5759b8a59073de2aa7772876f 100755 (executable)
@@ -33,9 +33,10 @@ See public-inbox-edit(1) man page for full documentation.
 EOF
 
 my $opt = { verbose => 1, all => 0, -min_inbox_version => 2, raw => 0 };
-my @opt = qw(mid|m=s file|F=s raw);
+my @opt = qw(mid|m=s file|F=s raw C=s@);
 GetOptions($opt, @PublicInbox::AdminEdit::OPT, @opt) or die $help;
 if ($opt->{help}) { print $help; exit 0 };
+PublicInbox::Admin::do_chdir(delete $opt->{C});
 
 my $cfg = PublicInbox::Config->new;
 my $editor = $ENV{MAIL_EDITOR}; # e.g. "mutt -f"
index 327980d28051d80350b99cc8dd584fad9cf0e58f..1572a1d23d82dad663a81956c3b95ea955ee13f0 100755 (executable)
@@ -30,7 +30,7 @@ GetOptions($opt, qw(verbose|v+ reindex rethread compact|c+ jobs|j=i
                indexlevel|index-level|L=s max_size|max-size=s
                batch_size|batch-size=s
                dedupe:s@ gc commit-interval=i watch scan! dry-run|n
-               all help|h))
+               all C=s@ help|h))
        or die $help;
 if ($opt->{help}) { print $help; exit 0 };
 die "--jobs must be >= 0\n" if defined $opt->{jobs} && $opt->{jobs} < 0;
@@ -40,6 +40,7 @@ STDERR->autoflush(1);
 local $SIG{USR1} = 'IGNORE'; # to be overridden in eidx_sync
 # require lazily to speed up --help
 require PublicInbox::Admin;
+PublicInbox::Admin::do_chdir(delete $opt->{C});
 my $cfg = PublicInbox::Config->new;
 my $eidx_dir = shift(@ARGV);
 unless (defined $eidx_dir) {
index 0034d44cbd36b69cbe16d9c3dd344b6bcb245d84..ca190a2e32d03fed0bb4200903a771cedb645bd7 100755 (executable)
@@ -42,7 +42,7 @@ GetOptions($opt, qw(verbose|v+ reindex rethread compact|c+ jobs|j=i prune
                batch_size|batch-size=s
                sequential-shard|seq-shard
                no-update-extindex update-extindex|E=s@
-               fast-noop|F skip-docdata all help|h))
+               fast-noop|F skip-docdata all C=s@ help|h))
        or die $help;
 if ($opt->{help}) { print $help; exit 0 };
 die "--jobs must be >= 0\n" if defined $opt->{jobs} && $opt->{jobs} < 0;
@@ -56,6 +56,7 @@ if ($opt->{reindex} && delete($opt->{'fast-noop'})) {
 # require lazily to speed up --help
 require PublicInbox::Admin;
 PublicInbox::Admin::require_or_die('-index');
+PublicInbox::Admin::do_chdir(delete $opt->{C});
 
 my $cfg = PublicInbox::Config->new; # Config is loaded by Admin
 $opt->{-use_cwd} = 1;
index 78a4d3bd75748f65110bb3e8af18c7d4fc976df8..1223d47ef2c1e76f6c27163267d6fbcedae9cf15 100755 (executable)
@@ -36,7 +36,7 @@ PublicInbox::Admin::require_or_die('-base');
 my ($version, $indexlevel, $skip_epoch, $skip_artnum, $jobs, $show_help);
 my $skip_docdata;
 my $ng = '';
-my @c_extra;
+my (@c_extra, @chdir);
 my %opts = (
        'V|version=i' => \$version,
        'L|index-level|indexlevel=s' => \$indexlevel,
@@ -47,6 +47,7 @@ my %opts = (
        'skip-docdata' => \$skip_docdata,
        'help|h' => \$show_help,
        'c=s@' => \@c_extra,
+       'C=s@' => \@chdir,
 );
 my $usage_cb = sub {
        print STDERR $help;
@@ -59,6 +60,7 @@ my $inboxdir = shift @ARGV or $usage_cb->();
 my $http_url = shift @ARGV or $usage_cb->();
 my (@address) = @ARGV;
 @address or $usage_cb->();
++PublicInbox::Admin::do_chdir(\@chdir);
 
 @c_extra = map {
        my ($k, $v) = split(/=/, $_, 2);
index 59c03150c67ce6bcac70d60dca97e0d79af3a308..121027ccbaa7493a06b6a79a91d0fc328ac887dc 100755 (executable)
@@ -26,9 +26,10 @@ See public-inbox-purge(1) man page for full documentation.
 EOF
 
 my $opt = { verbose => 1, all => 0, -min_inbox_version => 2 };
-GetOptions($opt, @PublicInbox::AdminEdit::OPT) or die $help;
+GetOptions($opt, @PublicInbox::AdminEdit::OPT, 'C=s@') or die $help;
 if ($opt->{help}) { print $help; exit 0 };
 
+PublicInbox::Admin::do_chdir(delete $opt->{C});
 my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt);
 PublicInbox::AdminEdit::check_editable(\@ibxs);
 
index 81d1a85bc289703a6e78d0471e43764d953005de..24fc5a252b4e7e6415b0521c29472319e8218376 100755 (executable)
@@ -33,11 +33,12 @@ GetOptions($opt, qw(
        sequential-shard|seq-shard
        jobs|j=i quiet|q verbose|v
        blocksize|b=s no-full|n fuller|F
-       all help|h)) or die $help;
+       all C=s@ help|h)) or die $help;
 if ($opt->{help}) { print $help; exit 0 };
 
 use PublicInbox::Admin;
 PublicInbox::Admin::require_or_die('-search');
+PublicInbox::Admin::do_chdir(delete $opt->{C});
 
 require PublicInbox::Config;
 my $cfg = PublicInbox::Config->new;