From d17e8369ca11e7816772d074b284933adbba38e4 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Fri, 3 Oct 2014 21:58:31 +0200 Subject: format optional arguments in square brakets --- lib/Monitoring/Plugin/Getopt.pm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/Monitoring') 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 my ($self, $spec, $label) = @_; my ($opts, $type) = split /=|:/, $spec, 2; + my $optional = ($spec =~ m/:/); my (@short, @long); for (split /\|/, $opts) { if (length $_ == 1) { @@ -93,11 +94,20 @@ sub _spec_to_help my $help = join(', ', @short, @long); if ($type) { - if ($label) { - $help .= '=' . $label; + if (!$label) { + if ($type eq 'i' || $type eq '+' || $type =~ /\d+/) { + $label = 'INTEGER'; + } + else { + $label = 'STRING'; + } + } + + if ($optional) { + $help .= '[=' . $label . ']'; } else { - $help .= ($type eq 'i' || $type eq '+' || $type =~ /\d+/) ? '=INTEGER' : '=STRING'; + $help .= '=' . $label; } } elsif ($label) { -- cgit v1.2.3-74-g34f1