summaryrefslogtreecommitdiffstats
path: root/lib/Monitoring
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.org>2016-11-20 16:56:04 +0100
committerGitHub <noreply@github.com>2016-11-20 16:56:04 +0100
commitc03943635354cf1fe4d1d6e5d1a5c60acd6126db (patch)
treeef2245ad08a29d5cad77b1ce5bdd367b54df6ab7 /lib/Monitoring
parentc79f65a91e58b84629c2c76be49e47fc34e274a6 (diff)
parentfac40fb90fc4129704de775786fd3310bad3f8bf (diff)
downloadmonitoring-plugin-perl-c03943635354cf1fe4d1d6e5d1a5c60acd6126db.tar.gz
Merge pull request #13 from mstock/feature/argument-negation
Allow negation of command line arguments using '--no'-prefix
Diffstat (limited to 'lib/Monitoring')
-rw-r--r--lib/Monitoring/Plugin/Getopt.pm12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/Monitoring/Plugin/Getopt.pm b/lib/Monitoring/Plugin/Getopt.pm
index 106600a..9452058 100644
--- a/lib/Monitoring/Plugin/Getopt.pm
+++ b/lib/Monitoring/Plugin/Getopt.pm
@@ -81,14 +81,15 @@ sub _spec_to_help
81{ 81{
82 my ($self, $spec, $label) = @_; 82 my ($self, $spec, $label) = @_;
83 83
84 my ($opts, $type) = split /=|:/, $spec, 2; 84 my ($opts, $type) = split /=|:|!/, $spec, 2;
85 my $optional = ($spec =~ m/:/); 85 my $optional = ($spec =~ m/:/);
86 my $boolean = ($spec =~ m/!/);
86 my (@short, @long); 87 my (@short, @long);
87 for (split /\|/, $opts) { 88 for (split /\|/, $opts) {
88 if (length $_ == 1) { 89 if (length $_ == 1) {
89 push @short, "-$_"; 90 push @short, "-$_";
90 } else { 91 } else {
91 push @long, "--$_"; 92 push @long, $boolean ? "--[no-]$_" : "--$_";
92 } 93 }
93 } 94 }
94 95
@@ -207,7 +208,7 @@ sub _process_specs_getopt_long
207 # Setup names and defaults 208 # Setup names and defaults
208 my $spec = $arg->{spec}; 209 my $spec = $arg->{spec};
209 # Use first arg as name (like Getopt::Long does) 210 # Use first arg as name (like Getopt::Long does)
210 $spec =~ s/[=:].*$//; 211 $spec =~ s/[=:!].*$//;
211 my $name = (split /\s*\|\s*/, $spec)[0]; 212 my $name = (split /\s*\|\s*/, $spec)[0];
212 $arg->{name} = $name; 213 $arg->{name} = $name;
213 if (defined $self->{$name}) { 214 if (defined $self->{$name}) {
@@ -697,7 +698,8 @@ but basically it is a series of one or more argument names for this argument
697(separated by '|'), suffixed with an '=<type>' indicator if the argument 698(separated by '|'), suffixed with an '=<type>' indicator if the argument
698takes a value. '=s' indicates a string argument; '=i' indicates an integer 699takes a value. '=s' indicates a string argument; '=i' indicates an integer
699argument; appending an '@' indicates multiple such arguments are accepted; 700argument; appending an '@' indicates multiple such arguments are accepted;
700and so on. The following are some examples: 701appending an '!' indicates negation using '--no'-prefix is possible; and so on.
702The following are some examples:
701 703
702=over 4 704=over 4
703 705
@@ -709,6 +711,8 @@ and so on. The following are some examples:
709 711
710=item exclude|X=s@ 712=item exclude|X=s@
711 713
714=item perfdata!
715
712=item verbose|v+ 716=item verbose|v+
713 717
714=back 718=back