Move usage generation to a separate function
This commit is contained in:
parent
bd688e9750
commit
b4c4b5dc54
1 changed files with 17 additions and 10 deletions
27
ddclient.in
27
ddclient.in
|
@ -1248,12 +1248,12 @@ my @opt = (
|
||||||
);
|
);
|
||||||
|
|
||||||
sub main {
|
sub main {
|
||||||
my $opt_usage = process_args(@opt);
|
process_args(@opt);
|
||||||
$saved_recap = '';
|
$saved_recap = '';
|
||||||
%saved_opt = %opt;
|
%saved_opt = %opt;
|
||||||
$result = 'OK';
|
$result = 'OK';
|
||||||
if (opt('help')) {
|
if (opt('help')) {
|
||||||
printf "%s\n", $opt_usage;
|
print(usage(@opt), "\n");
|
||||||
$opt{'version'}('', '');
|
$opt{'version'}('', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2093,18 +2093,12 @@ sub init_config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
######################################################################
|
sub usage {
|
||||||
## process_args -
|
|
||||||
######################################################################
|
|
||||||
sub process_args {
|
|
||||||
my @spec = ();
|
|
||||||
my $usage = "";
|
my $usage = "";
|
||||||
for (@_) {
|
for (@_) {
|
||||||
if (ref $_) {
|
if (ref $_) {
|
||||||
my ($key, $specifier, $arg_usage) = @$_;
|
my ($key, $specifier, $arg_usage) = @$_;
|
||||||
my $value = default($key);
|
my $value = default($key);
|
||||||
push @spec, $key . $specifier;
|
|
||||||
$opt{$key} //= undef;
|
|
||||||
next unless $arg_usage;
|
next unless $arg_usage;
|
||||||
$usage .= " $arg_usage";
|
$usage .= " $arg_usage";
|
||||||
if (defined($value) && $value ne '') {
|
if (defined($value) && $value ne '') {
|
||||||
|
@ -2123,10 +2117,23 @@ sub process_args {
|
||||||
}
|
}
|
||||||
$usage .= "\n";
|
$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)) {
|
if (!GetOptions(\%opt, @spec)) {
|
||||||
$opt{"help"} = 1;
|
$opt{"help"} = 1;
|
||||||
}
|
}
|
||||||
return $usage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
Loading…
Reference in a new issue