summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.org>2017-12-22 11:49:49 +0100
committerGitHub <noreply@github.com>2017-12-22 11:49:49 +0100
commit00660dfc0c5536e13f090c3d391d53d5d87c1e81 (patch)
tree39d2fa19f8869c18bda07495703ba166ad79cb8c
parent4aa2aee51b54cb8988d87a01d1a3b9a0d90bb8bf (diff)
parentda6fe80e84a20aaf405a89bd0203d9ce1abc097d (diff)
downloadmonitoring-plugin-perl-00660dfc0c5536e13f090c3d391d53d5d87c1e81.tar.gz
Merge pull request #17 from tejr/arg-add-cleanup
Clean up argument adding code a little bit
-rw-r--r--lib/Monitoring/Plugin/Getopt.pm29
1 files changed, 13 insertions, 16 deletions
diff --git a/lib/Monitoring/Plugin/Getopt.pm b/lib/Monitoring/Plugin/Getopt.pm
index 262e3c8..c8033d0 100644
--- a/lib/Monitoring/Plugin/Getopt.pm
+++ b/lib/Monitoring/Plugin/Getopt.pm
@@ -382,27 +382,24 @@ sub arg
382 my $self = shift; 382 my $self = shift;
383 my %args; 383 my %args;
384 384
385 # Named args 385 # Param name to required boolean
386 if ($_[0] =~ m/^(spec|help|required|default|label)$/ && scalar(@_) % 2 == 0) { 386 my %params = (
387 %args = validate( @_, { 387 spec => 1,
388 spec => 1, 388 help => 1,
389 help => 1, 389 default => 0,
390 default => 0,
391 required => 0, 390 required => 0,
392 label => 0, 391 label => 0,
393 }); 392 );
393
394 # Named args
395 if (exists $params{$_[0]} && @_ % 2 == 0) {
396 %args = validate( @_, \%params );
394 } 397 }
395 398
396 # Positional args 399 # Positional args
397 else { 400 else {
398 my @args = validate_pos(@_, 1, 1, 0, 0, 0); 401 my @order = qw(spec help default required label);
399 %args = ( 402 @args{@order} = validate_pos(@_, @params{@order});
400 spec => $args[0],
401 help => $args[1],
402 default => $args[2],
403 required => $args[3],
404 label => $args[4],
405 );
406 } 403 }
407 404
408 # Add to private args arrayref 405 # Add to private args arrayref