Improve readability via minor logic tweaks

Change some code that is unnecessarily complicated or otherwise not
the right tool for the job to improve readability.
This commit is contained in:
Richard Hansen 2024-06-22 00:20:24 -04:00
parent ab60675660
commit 9a5500a667

View file

@ -1790,11 +1790,11 @@ sub _read_config {
} }
%passwords = (); %passwords = ();
if (exists($locals{'host'})) { if (exists($locals{'host'})) {
$args[0] = @args ? "$args[0],$locals{host}" : "$locals{host}"; $args[0] = (@args ? "$args[0]," : '') . $locals{host};
} }
## accumulate globals ## accumulate globals
if ($#args < 0) { if (!@args) {
map { $globals{$_} = $locals{$_} } keys %locals; %globals = (%globals, %locals);
next; next;
} }
@ -1810,16 +1810,10 @@ sub _read_config {
## allow {host} to be a comma separated list of hosts ## allow {host} to be a comma separated list of hosts
for my $h (split_by_comma($host)) { for my $h (split_by_comma($host)) {
if ($config{$h}) { $config{$h} = {%locals, %{$config{$h} // {}}};
## host already defined, merging configs
$config{$h} = {%locals, %{$config{$h}}};
} else {
## save a copy of the current globals
$config{$h} = {%locals};
$config{$h}{'host'} = $h; $config{$h}{'host'} = $h;
} }
} }
}
close(FD); close(FD);
warning("file ends while expecting a continuation line.") warning("file ends while expecting a continuation line.")
@ -1927,7 +1921,7 @@ sub init_config {
@hosts = split_by_comma($opt{'host'}); @hosts = split_by_comma($opt{'host'});
} }
if (opt('retry')) { if (opt('retry')) {
@hosts = map { $_ if ($cache{$_}{'status'} // '') ne 'good' } keys %cache; @hosts = grep(($cache{$_}{'status'} // '') ne 'good', keys(%cache));
} }
## remove any other hosts ## remove any other hosts
@ -1955,10 +1949,7 @@ sub init_config {
## now the host definitions... ## now the host definitions...
HOST: HOST:
for my $h (keys %config) { for my $h (keys %config) {
my $proto; my $proto = opt('protocol', $h);
$proto = $config{$h}{'protocol'};
$proto = opt('protocol') if !defined($proto);
load_sha1_support($proto) if (grep(/^$proto$/, ("freedns", "nfsn"))); load_sha1_support($proto) if (grep(/^$proto$/, ("freedns", "nfsn")));
load_json_support($proto) if (grep(/^$proto$/, ("1984", "cloudflare", "digitalocean", "gandi", "godaddy", "hetzner", "yandex", "nfsn", "njalla", "porkbun", "dnsexit2"))); load_json_support($proto) if (grep(/^$proto$/, ("1984", "cloudflare", "digitalocean", "gandi", "godaddy", "hetzner", "yandex", "nfsn", "njalla", "porkbun", "dnsexit2")));
@ -2005,7 +1996,7 @@ sub process_args {
push @spec, $key . $specifier; push @spec, $key . $specifier;
## define the default value which can be overwritten later ## define the default value which can be overwritten later
$opt{$key} = undef unless exists($opt{$key}); $opt{$key} //= undef;
next unless $arg_usage; next unless $arg_usage;