diff options
author | Eric Wong (Contractor, The Linux Foundation) <e@80x24.org> | 2019-06-09 02:51:45 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-06-09 04:33:16 +0000 |
commit | dca54e63b75aac956c7db1330b6d2868340273d5 (patch) | |
tree | 06a3769fb2f7c8fabbfbc03b1db935fce1e770f1 /lib/PublicInbox/Admin.pm | |
parent | 455a1c0ef0519b2048c34d2fb31c9e9adbe3f507 (diff) | |
download | public-inbox-dca54e63b75aac956c7db1330b6d2868340273d5.tar.gz |
admin: expose ->config
No point in forcing admin programs to reparse the config themselves; and we won't support multiple instances of it; unlike the WWW code.
Diffstat (limited to 'lib/PublicInbox/Admin.pm')
-rw-r--r-- | lib/PublicInbox/Admin.pm | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm index cebd1440..8a2f2043 100644 --- a/lib/PublicInbox/Admin.pm +++ b/lib/PublicInbox/Admin.pm @@ -9,6 +9,8 @@ use warnings; use Cwd 'abs_path'; use base qw(Exporter); our @EXPORT_OK = qw(resolve_repo_dir); +my $CFG; # all the admin stuff is a singleton +require PublicInbox::Config; sub resolve_repo_dir { my ($cd, $ver) = @_; @@ -78,24 +80,25 @@ sub unconfigured_ibx ($$) { }); } +sub config () { $CFG //= eval { PublicInbox::Config->new } } + sub resolve_inboxes ($;$) { my ($argv, $opt) = @_; - require PublicInbox::Config; require PublicInbox::Inbox; $opt ||= {}; - my $config = eval { PublicInbox::Config->new }; + my $cfg = config(); if ($opt->{all}) { my $cfgfile = PublicInbox::Config::default_file(); - $config or die "--all specified, but $cfgfile not readable\n"; + $cfg or die "--all specified, but $cfgfile not readable\n"; @$argv and die "--all specified, but directories specified\n"; } my $min_ver = $opt->{-min_inbox_version} || 0; my (@old, @ibxs); my %dir2ibx; - if ($config) { - $config->each_inbox(sub { + if ($cfg) { + $cfg->each_inbox(sub { my ($ibx) = @_; $ibx->{version} ||= 1; $dir2ibx{abs_path($ibx->{mainrepo})} = $ibx; |