summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Monitoring/Plugin/Getopt.pm16
-rw-r--r--t/Monitoring-Plugin-Getopt-04.t8
2 files changed, 17 insertions, 7 deletions
diff --git a/lib/Monitoring/Plugin/Getopt.pm b/lib/Monitoring/Plugin/Getopt.pm
index e09ff62..3575ce6 100644
--- a/lib/Monitoring/Plugin/Getopt.pm
+++ b/lib/Monitoring/Plugin/Getopt.pm
@@ -82,6 +82,7 @@ sub _spec_to_help
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 (@short, @long); 86 my (@short, @long);
86 for (split /\|/, $opts) { 87 for (split /\|/, $opts) {
87 if (length $_ == 1) { 88 if (length $_ == 1) {
@@ -93,11 +94,20 @@ sub _spec_to_help
93 94
94 my $help = join(', ', @short, @long); 95 my $help = join(', ', @short, @long);
95 if ($type) { 96 if ($type) {
96 if ($label) { 97 if (!$label) {
97 $help .= '=' . $label; 98 if ($type eq 'i' || $type eq '+' || $type =~ /\d+/) {
99 $label = 'INTEGER';
100 }
101 else {
102 $label = 'STRING';
103 }
104 }
105
106 if ($optional) {
107 $help .= '[=' . $label . ']';
98 } 108 }
99 else { 109 else {
100 $help .= ($type eq 'i' || $type eq '+' || $type =~ /\d+/) ? '=INTEGER' : '=STRING'; 110 $help .= '=' . $label;
101 } 111 }
102 } 112 }
103 elsif ($label) { 113 elsif ($label) {
diff --git a/t/Monitoring-Plugin-Getopt-04.t b/t/Monitoring-Plugin-Getopt-04.t
index 9b51883..2c91e23 100644
--- a/t/Monitoring-Plugin-Getopt-04.t
+++ b/t/Monitoring-Plugin-Getopt-04.t
@@ -118,8 +118,8 @@ like($@, qr/\n -H, --hostname=ADDRESS\n Hostname\n/, 'hostname ok');
118like($@, qr/\n --avatar=AVATAR\n Avatar\n/, 'avatar ok'); 118like($@, qr/\n --avatar=AVATAR\n Avatar\n/, 'avatar ok');
119like($@, qr/\n --disk=BYTES\n Disk limit in BYTES\n --disk=PERCENT%\n Disk limit in PERCENT\n --disk=STRING\n Disk limit in FOOBARS \(Default: 1024\)\n/, 'disk multiline ok'); 119like($@, qr/\n --disk=BYTES\n Disk limit in BYTES\n --disk=PERCENT%\n Disk limit in PERCENT\n --disk=STRING\n Disk limit in FOOBARS \(Default: 1024\)\n/, 'disk multiline ok');
120like($@, qr/\n --limit=STRING\n Limit in BYTES\n --limit=PERCENT%\n Limit in PERCENT\n/, 'limit multiline ok'); 120like($@, qr/\n --limit=STRING\n Limit in BYTES\n --limit=PERCENT%\n Limit in PERCENT\n/, 'limit multiline ok');
121like($@, qr/\n -d, --dirport=INTEGER/, 'dirport ok'); 121like($@, qr/\n -d, --dirport\[=INTEGER\]/, 'dirport ok');
122like($@, qr/\n -s, --enablesomething=STRING/, 'enablesomething ok'); 122like($@, qr/\n -s, --enablesomething\[=STRING\]/, 'enablesomething ok');
123like($@, qr/\n -T, --testtimeout=INTEGER/, 'testtimeout ok'); 123like($@, qr/\n -T, --testtimeout\[=INTEGER\]/, 'testtimeout ok');
124like($@, qr/\n -v, --verbosity=INTEGER/, 'verbosity ok'); 124like($@, qr/\n -v, --verbosity\[=INTEGER\]/, 'verbosity ok');
125#print $@; 125#print $@;