Use protocol-specific default when known

Different protocols can have different default values for a particular
variable.  Grab the protocol-specific variable definition if given a
hostname when looking up the variable's default.
This commit is contained in:
Richard Hansen 2024-06-30 23:40:46 -04:00
parent 775b7fcbfe
commit fe1768316a

View file

@ -2350,7 +2350,12 @@ sub split_by_comma {
return ();
}
sub default {
my $v = shift;
my ($v, $h) = @_;
if (defined($h) && $config{$h}) {
my $proto = $protocols{$config{$h}{'protocol'}};
my $var = $proto->{variables}{$v} if $proto;
return $var->{default} if $var;
}
return undef if !defined($variables{'merged'}{$v});
# TODO: This might grab an arbitrary protocol-specific variable definition, which could cause
# surprising behavior.
@ -2363,7 +2368,7 @@ sub opt {
# TODO: Why check %opt before %globals? Valid variables from %opt are merged into %globals by
# init_config(), so it shouldn't be necessary. Also, it runs the risk of collision with a
# non-variable command line option like `--version`, `--help`, etc.
return $opt{$v} // $globals{$v} // default($v);
return $opt{$v} // $globals{$v} // default($v, $h);
}
sub min {
my $min = shift;