]> iEval git - app-statsbot.git/commitdiff
Support configuration via the environment
authorMarius Gavrilescu <marius@ieval.ro>
Thu, 24 Mar 2016 13:16:48 +0000 (15:16 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Thu, 24 Mar 2016 13:20:09 +0000 (15:20 +0200)
lib/App/Statsbot.pm
statsbot

index 902f9d336668bd930d7ad6bc87d8e4ef57ae9033..fcc79594eefc2656742758b52de94af9b3957aa3 100644 (file)
@@ -31,6 +31,15 @@ our $SSL = '';
 our @CHANNELS;
 our $DB = '/var/lib/statsbot/db';
 
+{
+       my %cfg = (debug => \$DEBUG, tick => \$TICK, nickname => \$NICKNAME, server => \$SERVER, port => \$PORT, ssl => \$SSL, channels => \@CHANNELS, db => \$DB);
+       for my $var (keys %cfg) {
+               my $key = "STATSBOT_\U$var";
+               ${$cfg{$var}} = $ENV{$key} if exists $ENV{$key} && ref $cfg{$var} eq 'SCALAR';
+               @{$cfg{$var}} = split ' ', $ENV{$key} if exists $ENV{$key} && ref $cfg{$var} eq 'ARRAY';
+       }
+}
+
 my $dbh;
 my $insert;
 my $update;
@@ -198,6 +207,11 @@ a channel. It is able to answer queries of the form "In the last <time
 interval>, how much time did <nick> spend in this channel?".
 
 It is configured via global variables in the App::Statsbot package.
+These variables are initialized from environment variables with names
+of the form STATSBOT_DEBUG, STATSBOT_TICK, etc. In the case of array
+variables, the environment variable is treated as a space separated
+list. Each configuration variable has a default value used when it is
+not set explicitly or via the environment.
 
 =over
 
index 2545fc507e75ff6d18d755a6bbb173e5c277d53d..4c06d1a407f972a2fc08c366af8d4d908ec74f4b 100755 (executable)
--- a/statsbot
+++ b/statsbot
@@ -96,6 +96,46 @@ not exist. Defaults to C</var/lib/statsbot/db>.
 
 =back
 
+=head1 ENVIRONMENT
+
+All options can be passed via the environment. If an option is passed both as an environment variable and as an argument, the argument takes priority.
+
+=over
+
+=item B<STATSBOT_DEBUG>=I<1>
+
+Equivalent to B<--debug>.
+
+=item B<STATSBOT_TICK>=I<60>
+
+Equivalent to B<--tick>=I<60>.
+
+=item B<STATSBOT_NICKNAME>=I<"timebot">
+
+Equivalent to B<--nickname>=I<"timebot">.
+
+=item B<STATSBOT_SERVER>=I<"irc.oftc.net">
+
+Equivalent to B<--server>=I<"irc.oftc.net">.
+
+=item B<STATSBOT_PORT>=I<6697>
+
+Equivalent to B<--port>=I<6697>.
+
+=item B<STATSBOT_SSL>=I<1>
+
+Equivalent to B<--ssl>.
+
+=item B<STATSBOT_CHANNELS>=I<"#mychan #otherchan">
+
+Equivalent to B<--channel>=I<#mychan> B<--channel>=I<#otherchan>.
+
+=item B<STATSBOT_DB>=I<"/path/to/some/file.sqlite">
+
+Equivalent to B<--db>=I<"/path/to/some/file.sqlite">.
+
+=back
+
 =head1 SEE ALSO
 
 L<App::Statsbot>
This page took 0.02443 seconds and 4 git commands to generate.