From: Guilhem Moulin Date: Thu, 23 Jul 2015 18:12:38 +0000 (+0200) Subject: Add a command-line option --config to specify the configuration file. X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=c7e3736d35527593235ae12bf6e879689ea17f66;p=interimap.git Add a command-line option --config to specify the configuration file. --- diff --git a/imapsync b/imapsync index 4ef47b3..a18e4cd 100755 --- a/imapsync +++ b/imapsync @@ -43,11 +43,11 @@ sub usage(;$) { print STDERR "TODO $NAME usage\n"; exit $rv; } -usage(1) unless GetOptions(\%CONFIG, qw/debug help|h quiet|q oneshot|1/); +usage(1) unless GetOptions(\%CONFIG, qw/debug help|h config=s quiet|q oneshot|1/); usage(0) if $CONFIG{help}; -my $CONFFILE = 'sync.ini'; +my $CONFFILE = delete $CONFIG{config} // 'imapsync'; my $CACHEDIR = './imapsync.cache'; # XXX use a config option my $DBFILE = "$CACHEDIR/imap.guilhem.org.db"; my $LOCKFILE = "$CACHEDIR/.imap.guilhem.org.lck"; diff --git a/lib/Net/IMAP/Sync.pm b/lib/Net/IMAP/Sync.pm index 0228f29..61930e7 100644 --- a/lib/Net/IMAP/Sync.pm +++ b/lib/Net/IMAP/Sync.pm @@ -65,6 +65,9 @@ sub read_config($$%) { my $section = shift; my %opts = (%OPTIONS, @_); + $conffile = ($ENV{XDG_CONFIG_HOME} // "$ENV{HOME}/.config") .'/'. $conffile + unless $conffile =~ /\A\//; # relative path + die "No such config file $conffile\n" unless defined $conffile and -f $conffile and -r $conffile;