From: Eric Wong Date: Thu, 20 Aug 2020 20:24:38 +0000 (+0000) Subject: init: support --help and -? X-Git-Tag: v1.6.0~130 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=3f3867da5e5ff10b941e942c9974ddbf1e5464c1 init: support --help and -? And speed those up with some lazy loading, too. --- diff --git a/script/public-inbox-init b/script/public-inbox-init index 1c8066df..6852f64a 100755 --- a/script/public-inbox-init +++ b/script/public-inbox-init @@ -1,57 +1,76 @@ -#!/usr/bin/perl -w +#!perl -w # Copyright (C) 2014-2020 all contributors # License: AGPL-3.0+ -# -# Initializes a public-inbox, basically a wrapper for git-init(1) use strict; -use warnings; -sub usage { - print STDERR < \$version, 'L|index-level|indexlevel=s' => \$indexlevel, 'S|skip|skip-epoch=i' => \$skip_epoch, 'N|skip-artnum=i' => \$skip_artnum, 'j|jobs=i' => \$jobs, + 'help|?' => \$show_help, ); -GetOptions(%opts) or usage(); +my $usage_cb = sub { + print STDERR "Usage: $usage\n"; + exit 1; +}; +GetOptions(%opts) or $usage_cb->(); +if ($show_help) { print $help; exit 0 }; PublicInbox::Admin::indexlevel_ok_or_die($indexlevel) if defined $indexlevel; -my $name = shift @ARGV or usage(); -my $inboxdir = shift @ARGV or usage(); -my $http_url = shift @ARGV or usage(); +my $name = shift @ARGV or $usage_cb->(); +my $inboxdir = shift @ARGV or $usage_cb->(); +my $http_url = shift @ARGV or $usage_cb->(); my (@address) = @ARGV; -@address or usage(); +@address or $usage_cb->(); my %seen; +require PublicInbox::Config; my $pi_config = PublicInbox::Config->default_file; -my $dir = dirname($pi_config); -mkpath($dir); # will croak on fatal errors +require File::Basename; +my $dir = File::Basename::dirname($pi_config); +require File::Path; +File::Path::mkpath($dir); # will croak on fatal errors # first, we grab a flock to prevent simultaneous public-inbox-init # processes from trampling over each other, or exiting with 255 on # O_EXCL failure below. This gets unlocked automatically on exit: +require PublicInbox::Lock; my $lock_obj = { lock_path => "$pi_config.flock" }; PublicInbox::Lock::lock_acquire($lock_obj); # git-config will operate on this (and rename on success): +require File::Temp; my $fh = File::Temp->new(TEMPLATE => 'pi-init-XXXXXXXX', DIR => $dir); # Now, we grab another lock to use git-config(1) locking, so it won't @@ -111,7 +130,8 @@ close($fh) or die "failed to close $pi_config_tmp: $!\n"; my $pfx = "publicinbox.$name"; my @x = (qw/git config/, "--file=$pi_config_tmp"); -$inboxdir = abs_path($inboxdir); +require Cwd; +$inboxdir = Cwd::abs_path($inboxdir); die "`\\n' not allowed in `$inboxdir'\n" if $inboxdir =~ /\n/s; if (-f "$inboxdir/inbox.lock") { if (!defined $version) { @@ -148,6 +168,7 @@ if (defined $jobs) { $creat_opt->{nproc} = $jobs; } +require PublicInbox::InboxWritable; $ibx = PublicInbox::InboxWritable->new($ibx, $creat_opt); $ibx->init_inbox(0, $skip_epoch, $skip_artnum);