From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 1AA821FB06 for ; Wed, 15 Sep 2021 21:36:00 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/5] support -C (chdir) for most non-daemon commands Date: Wed, 15 Sep 2021 21:35:59 +0000 Message-Id: <20210915213559.21757-6-e@80x24.org> In-Reply-To: <20210915213559.21757-1-e@80x24.org> References: <20210915213559.21757-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 3 ++- script/public-inbox-convert | 6 +++--- script/public-inbox-edit | 3 ++- script/public-inbox-extindex | 3 ++- script/public-inbox-index | 3 ++- script/public-inbox-init | 4 +++- script/public-inbox-purge | 3 ++- script/public-inbox-xcpdb | 3 ++- 8 files changed, 18 insertions(+), 10 deletions(-) diff --git a/script/public-inbox-compact b/script/public-inbox-compact index 6e34aaeb..80d0224b 100755 --- a/script/public-inbox-compact +++ b/script/public-inbox-compact @@ -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; diff --git a/script/public-inbox-convert b/script/public-inbox-convert index 01af846a..42955a48 100755 --- a/script/public-inbox-convert +++ b/script/public-inbox-convert @@ -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; diff --git a/script/public-inbox-edit b/script/public-inbox-edit index 9498038b..1fbaf5a7 100755 --- a/script/public-inbox-edit +++ b/script/public-inbox-edit @@ -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" diff --git a/script/public-inbox-extindex b/script/public-inbox-extindex index 327980d2..1572a1d2 100755 --- a/script/public-inbox-extindex +++ b/script/public-inbox-extindex @@ -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) { diff --git a/script/public-inbox-index b/script/public-inbox-index index 0034d44c..ca190a2e 100755 --- a/script/public-inbox-index +++ b/script/public-inbox-index @@ -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; diff --git a/script/public-inbox-init b/script/public-inbox-init index 78a4d3bd..1223d47e 100755 --- a/script/public-inbox-init +++ b/script/public-inbox-init @@ -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); diff --git a/script/public-inbox-purge b/script/public-inbox-purge index 59c03150..121027cc 100755 --- a/script/public-inbox-purge +++ b/script/public-inbox-purge @@ -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); diff --git a/script/public-inbox-xcpdb b/script/public-inbox-xcpdb index 81d1a85b..24fc5a25 100755 --- a/script/public-inbox-xcpdb +++ b/script/public-inbox-xcpdb @@ -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;