aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Terjan <pterjan@mageia.org>2017-10-04 20:04:10 +0100
committerPascal Terjan <pterjan@mageia.org>2017-10-04 20:04:57 +0100
commit435e218e4dcc413e1d74f1ad39c7882de5b9b7ee (patch)
tree9947c81fe0a312b1ddf167b01333e584e0367aaf
parent4542dfad9d493f42e8b9c1c2b2da476f0e7ff815 (diff)
downloadiurt-435e218e4dcc413e1d74f1ad39c7882de5b9b7ee.tar
iurt-435e218e4dcc413e1d74f1ad39c7882de5b9b7ee.tar.gz
iurt-435e218e4dcc413e1d74f1ad39c7882de5b9b7ee.tar.bz2
iurt-435e218e4dcc413e1d74f1ad39c7882de5b9b7ee.tar.xz
iurt-435e218e4dcc413e1d74f1ad39c7882de5b9b7ee.zip
Allow overriding true config values with false
-rw-r--r--NEWS2
-rw-r--r--lib/Iurt/Config.pm14
-rw-r--r--t/config.t40
3 files changed, 53 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 6a86701..22649d8 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,7 @@
- iurt: bring lo up in the chroot and point hostname to 127.0.0.1
- iurt: add an option to disable the use of network namespaces
+- iurt, ulri, emi: allow overriding a true config value with a false
+ one and add some tests.
0.7.1
- iurt: also use --urpmi-root for urpmi.addmedia
diff --git a/lib/Iurt/Config.pm b/lib/Iurt/Config.pm
index 9a4ed8b..32b87e4 100644
--- a/lib/Iurt/Config.pm
+++ b/lib/Iurt/Config.pm
@@ -60,7 +60,7 @@ sub config_usage {
print "\n\n";
}
-=head2 config_init($config_usage, $config, $rung)
+=head2 config_init($config_usage, $config, $run)
Create an instance of a class at runtime.
I<$config_usage> is the configuration help,
@@ -75,7 +75,11 @@ sub config_init {
foreach my $k (keys %$config_usage) {
ref $config_usage->{$k}{default} eq 'CODE' and next;
- $config->{$k} ||= $run->{config}{$k} || $config_usage->{$k}{default};
+ if (defined($run->{config}{$k})) {
+ $config->{$k} = $run->{config}{$k};
+ } elsif (!defined($config->{$k})) {
+ $config->{$k} = $config_usage->{$k}{default};
+ }
}
# warly 20061107
# we need to have all the default initialised before calling functions, so this
@@ -83,7 +87,11 @@ sub config_init {
foreach my $k (keys %$config_usage) {
ref $config_usage->{$k}{default} eq 'CODE' or next;
my $a = $config_usage->{$k}{default}($config, $run);
- $config->{$k} ||= $run->{config}{$k} || $a;
+ if (defined($run->{config}{$k})) {
+ $config->{$k} = $run->{config}{$k};
+ } elsif (!defined($config->{$k})) {
+ $config->{$k} = $a;
+ }
}
}
diff --git a/t/config.t b/t/config.t
new file mode 100644
index 0000000..4ecb8a7
--- /dev/null
+++ b/t/config.t
@@ -0,0 +1,40 @@
+use Test::More;
+use Iurt::Config;
+
+my %config_usage = (
+ option_with_false_default => {
+ default => 0
+ },
+ option_with_true_default => {
+ default => 1
+ },
+);
+my $config = {
+ option_with_false_default => 1,
+ option_with_true_default => 0,
+};
+my %run;
+
+config_init(\%config_usage, $config, \%run);
+is($config->{option_with_false_default}, 1, 'false default and true in config file');
+is($config->{option_with_true_default}, 0, 'true default and false in config file');
+
+$config = {};
+$run{config}{option_with_false_default} = 1;
+$run{config}{option_with_true_default} = 0;
+
+config_init(\%config_usage, $config, \%run);
+is($config->{option_with_false_default}, 1, 'false default and true on cmdline');
+is($config->{option_with_true_default}, 0, 'true default and false on cmdline');
+
+$config = {
+ option_with_false_default => 1,
+ option_with_true_default => 0,
+};
+$run{config}{option_with_false_default} = 0;
+$run{config}{option_with_true_default} = 1;
+config_init(\%config_usage, $config, \%run);
+is($config->{option_with_false_default}, 0, 'false default, true in config file, false on cmdline');
+is($config->{option_with_true_default}, 1, 'true default, false in config file, true on cmdline');
+
+done_testing();