From b4c4b5dc5473ffcf1a1d80c2a6f228f58cdc376a Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 24 Jun 2024 02:14:18 -0400 Subject: [PATCH] Move usage generation to a separate function --- ddclient.in | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/ddclient.in b/ddclient.in index b5d110c..2e96a0d 100755 --- a/ddclient.in +++ b/ddclient.in @@ -1248,12 +1248,12 @@ my @opt = ( ); sub main { - my $opt_usage = process_args(@opt); + process_args(@opt); $saved_recap = ''; %saved_opt = %opt; $result = 'OK'; if (opt('help')) { - printf "%s\n", $opt_usage; + print(usage(@opt), "\n"); $opt{'version'}('', ''); } @@ -2093,18 +2093,12 @@ sub init_config { } } -###################################################################### -## process_args - -###################################################################### -sub process_args { - my @spec = (); +sub usage { my $usage = ""; for (@_) { if (ref $_) { my ($key, $specifier, $arg_usage) = @$_; my $value = default($key); - push @spec, $key . $specifier; - $opt{$key} //= undef; next unless $arg_usage; $usage .= " $arg_usage"; if (defined($value) && $value ne '') { @@ -2123,10 +2117,23 @@ sub process_args { } $usage .= "\n"; } + return $usage; +} + +###################################################################### +## process_args - +###################################################################### +sub process_args { + my @spec = (); + for (@_) { + next if !ref($_); + my ($key, $specifier) = @$_; + push @spec, $key . $specifier; + $opt{$key} //= undef; + } if (!GetOptions(\%opt, @spec)) { $opt{"help"} = 1; } - return $usage; } ######################################################################