mirror of https://github.com/schoebel/mars
gen_config: allow options to be overridden by environment
From caa2cd968be140ed3e91eeb0d30e0c006b55e17a Mon Sep 17 00:00:00 2001 From: Daniel Hermann <daniel.hermann@1und1.de> Date: Thu, 11 Jul 2013 11:45:16 +0200 Subject: [PATCH] gen_config: allow options to be overridden by environment
This commit is contained in:
parent
d70a415b9a
commit
5eae58a3a4
|
@ -16,11 +16,14 @@ my $DEBUG = 0;
|
|||
my $option;
|
||||
my $type;
|
||||
my @default;
|
||||
my %setByEnv;
|
||||
|
||||
while (my $line = <STDIN>) {
|
||||
if ($line =~ /^config\s+(\w+)\W*$/) {
|
||||
$option = $1;
|
||||
$setByEnv{$option} = $ENV{$option} if exists $ENV{$option};
|
||||
printf STDERR "OPTION: %s\n", $option if $DEBUG;
|
||||
printf STDERR "ENV: %s='%s'\n", $option, $setByEnv{$option} if $DEBUG && exists $ENV{$option};
|
||||
}
|
||||
elsif ($line =~ /^\s+(tristate|bool|int|string)\s+.*$/) {
|
||||
$type = $1;
|
||||
|
@ -79,6 +82,12 @@ foreach my $opt (@default) {
|
|||
my $optname = $opt->{option};
|
||||
my $optval = $opt->{value};
|
||||
|
||||
if (exists $setByEnv{$optname}) {
|
||||
print qq%
|
||||
/* CONFIG_$optname overridden by ENVIRONMENT */%;
|
||||
$optval = $setByEnv{$optname};
|
||||
}
|
||||
|
||||
if (!defined($optname) || !defined($optval)) {
|
||||
printf(STDERR "SKIPPED option due to missing parameters: optname=%s optval=%s\n",
|
||||
$optname||'', $optval||'');
|
||||
|
|
Loading…
Reference in New Issue