From f2aa8f510828ddfb165f84ecc13aaf29d7bdfb4d Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Thu, 31 Aug 2006 08:34:24 +0000 Subject: Support multiple -v options for verbosity level git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1472 f882894a-f735-0410-b71e-b25c423dba1c --- lib/Nagios/Plugin/Getopt.pm | 8 ++++---- t/Nagios-Plugin-Getopt-01.t | 13 ++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/Nagios/Plugin/Getopt.pm b/lib/Nagios/Plugin/Getopt.pm index d291b2f..1903e8c 100644 --- a/lib/Nagios/Plugin/Getopt.pm +++ b/lib/Nagios/Plugin/Getopt.pm @@ -41,8 +41,8 @@ my @ARGS = ({ help => "-t, --timeout=INTEGER\n Seconds before plugin times out (default: %s)", default => $DEFAULT{timeout}, }, { - spec => 'verbose|v', - help => "-v, --verbose\n Show details for command-line debugging", + spec => 'verbose|v+', + help => "-v, --verbose\n Show details for command-line debugging (can repeat up to 3 times)", default => $DEFAULT{verbose}, }, ); @@ -467,7 +467,7 @@ example: -t, --timeout=INTEGER Seconds before plugin times out (default: 15) -v, --verbose - Show details for command-line debugging + Show details for command-line debugging (can repeat up to 3 times) =head2 ARGUMENTS @@ -506,7 +506,7 @@ and so on. The following are some examples: =item exclude|X=s@ -=item verbose|v +=item verbose|v+ =back diff --git a/t/Nagios-Plugin-Getopt-01.t b/t/Nagios-Plugin-Getopt-01.t index fad68e3..b708a5f 100644 --- a/t/Nagios-Plugin-Getopt-01.t +++ b/t/Nagios-Plugin-Getopt-01.t @@ -2,7 +2,7 @@ use strict; -use Test::More tests => 72; +use Test::More tests => 76; BEGIN { use_ok('Nagios::Plugin::Getopt') }; my %PARAM = ( @@ -45,6 +45,17 @@ is($ng->warning, 3, 'warning set to 3'); is($ng->critical, 10, 'critical set to 10'); is($ng->timeout, 12, 'timeout set to 12'); +# Check multiple verbose flags +@ARGV = qw(-w 3 --critical 10 -v -v -v); +$ng = setup; +$ng->getopts; +is ($ng->verbose, 3, "Verbose set to level 3"); + +@ARGV = qw(-w 3 --critical 10 --verbose --verbose --verbose); +$ng = setup; +$ng->getopts; +is ($ng->verbose, 3, "Verbose set to level 3 (longhand)"); + # Missing args @ARGV = qw(); $ng = setup; -- cgit v1.2.3-74-g34f1