summaryrefslogtreecommitdiffstats
path: root/lib/Monitoring/Plugin/Getopt.pm
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.org>2014-12-28 14:05:08 +0100
committerSven Nierlein <sven@nierlein.org>2014-12-28 14:05:08 +0100
commit769c840bbd0bc2f40a5de014eba4ad85008969f7 (patch)
tree70ad00d3fe0755af4c416ffe0143ff37ed9a0596 /lib/Monitoring/Plugin/Getopt.pm
parent9b52e7531fa4b5b27e03e9d8985d847d81ee1e46 (diff)
parentd17e8369ca11e7816772d074b284933adbba38e4 (diff)
downloadmonitoring-plugin-perl-769c840bbd0bc2f40a5de014eba4ad85008969f7.tar.gz
Merge pull request #2 from evgeni/getopt_colon_spec
GetOpt::Long optional arguments using a colon instead of an equal sign
Diffstat (limited to 'lib/Monitoring/Plugin/Getopt.pm')
-rw-r--r--lib/Monitoring/Plugin/Getopt.pm18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/Monitoring/Plugin/Getopt.pm b/lib/Monitoring/Plugin/Getopt.pm
index 354f713..db98567 100644
--- a/lib/Monitoring/Plugin/Getopt.pm
+++ b/lib/Monitoring/Plugin/Getopt.pm
@@ -81,7 +81,8 @@ 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 (@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' ? '=INTEGER' : '=STRING'; 110 $help .= '=' . $label;
101 } 111 }
102 } 112 }
103 elsif ($label) { 113 elsif ($label) {