Rely on opt()
fallback if a value is invalid
This commit is contained in:
parent
2b65aff56b
commit
e8f0358bbb
1 changed files with 5 additions and 18 deletions
23
ddclient.in
23
ddclient.in
|
@ -1964,13 +1964,7 @@ sub init_config {
|
||||||
# TODO: Move this check to where the command-line options are actually processed.
|
# TODO: Move this check to where the command-line options are actually processed.
|
||||||
if (!eval { $globals{$k} = check_value($globals{$k}, $def); 1; }) {
|
if (!eval { $globals{$k} = check_value($globals{$k}, $def); 1; }) {
|
||||||
warning("ignoring invalid variable value '$k=$globals{$k}': $@");
|
warning("ignoring invalid variable value '$k=$globals{$k}': $@");
|
||||||
if ($def->{'required'}) {
|
delete($globals{$k});
|
||||||
# TODO: What's the point of this? The opt() function will fall back to the default
|
|
||||||
# value if $globals{$k} is undefined.
|
|
||||||
$globals{$k} = default($k);
|
|
||||||
} else {
|
|
||||||
$globals{$k} = undef;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1994,26 +1988,19 @@ sub init_config {
|
||||||
|
|
||||||
# TODO: This silently ignores unknown options passed via --options.
|
# TODO: This silently ignores unknown options passed via --options.
|
||||||
for my $k (keys %$svars) {
|
for my $k (keys %$svars) {
|
||||||
|
next if !defined($config{$h}{$k});
|
||||||
my $def = $svars->{$k};
|
my $def = $svars->{$k};
|
||||||
# TODO: Why doesn't this try %opt and %globals before falling back to the variable
|
|
||||||
# default? By ignoring %opt and %globals, `--options` will not have any effect on any
|
|
||||||
# hosts that are not specified on the command line (via `--host=a,b` and/or
|
|
||||||
# `--options=host=c,d`).
|
|
||||||
# TODO: Why not just leave $conf->{$k} undef? Then opt() would automatically fall back
|
|
||||||
# to %opt, %globals, or the variable default.
|
|
||||||
my $ovalue = $config{$h}{$k} // $def->{'default'};
|
|
||||||
# _read_config already checked any value from the config file, so the purpose of this
|
# _read_config already checked any value from the config file, so the purpose of this
|
||||||
# check is to validate command-line options from --options which were merged into
|
# check is to validate command-line options from --options which were merged into
|
||||||
# $config{$h} above.
|
# $config{$h} above.
|
||||||
# TODO: Move this check to where --options is actually processed.
|
# TODO: Move this check to where --options is actually processed.
|
||||||
if (!eval { $conf->{$k} = check_value($ovalue, $def); 1; }) {
|
if (!eval { $conf->{$k} = check_value($config{$h}{$k}, $def); 1; }) {
|
||||||
$ovalue //= '(not set)';
|
|
||||||
if ($def->{'required'}) {
|
if ($def->{'required'}) {
|
||||||
warning("skipping host $h: invalid variable value '$k=$ovalue': $@");
|
warning("skipping host $h: invalid variable value '$k=$config{$h}{$k}': $@");
|
||||||
delete $config{$h};
|
delete $config{$h};
|
||||||
next HOST;
|
next HOST;
|
||||||
} else {
|
} else {
|
||||||
warning("host $h: ignoring invalid variable value '$k=$ovalue': $@");
|
warning("host $h: ignoring invalid variable value '$k=$config{$h}{$k}': $@");
|
||||||
$conf->{$k} = undef;
|
$conf->{$k} = undef;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue