]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Config.pm
flesh out MDA and simplify config setup
[public-inbox.git] / lib / PublicInbox / Config.pm
index d91c28a91ab15e014e9db0e45b38091fe5bb8517..9ba4ad32901f501d011c6a88f531914471d98e09 100644 (file)
@@ -3,12 +3,13 @@
 package PublicInbox::Config;
 use strict;
 use warnings;
+use File::Path::Expand qw/expand_filename/;
 
 # returns key-value pairs of config directives in a hash
 sub new {
        my ($class, $file) = @_;
 
-       local $ENV{GIT_CONFIG} = $file;
+       local $ENV{GIT_CONFIG} = defined $file ? $file : default_file();
 
        my @cfg = `git config -l`;
        $? == 0 or die "git config -l failed: $?\n";
@@ -37,4 +38,11 @@ sub lookup {
        \%rv;
 }
 
+sub default_file {
+       my $f = $ENV{PI_CONFIG};
+       return $f if defined $f;
+       my $pi_dir = $ENV{PI_DIR} || expand_filename('~/.public-inbox/');
+       "$pi_dir/config";
+}
+
 1;