diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2010-09-05 16:21:10 +0200 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2010-09-05 16:21:10 +0200 |
commit | 0f3b5b657b95451f0c9328db053710c1edb782c6 (patch) | |
tree | 44d03184a9f9152a1fd3ecac334f5ce3f3196391 | |
parent | 61fc6dec5d7312dbfaf19e8ccffda705a128cad4 (diff) |
proper -v handling
-rwxr-xr-x | bin/icli | 42 | ||||
-rw-r--r-- | t/50-icli.t | 4 |
2 files changed, 20 insertions, 26 deletions
@@ -179,25 +179,16 @@ sub display_queue { sub display_service { my ($s) = @_; - given ($verbosity) { - when (1) { - printf( - "%-20.20s %s %s\n", - $s->{service_description}, - service_state($s->{has_been_checked}, $s->{current_state}), - $s->{plugin_output}, - ); - } - when (2) { - printf("%-20.20s %s %d/%d %s\n", - $s->{service_description}, - service_state($s->{has_been_checked}, $s->{current_state}), - $s->{current_attempt}, - $s->{max_attempts}, - $s->{plugin_output}, - ); - } + my $v = $verbosity; + + printf("%-20.20s", $s->{service_description}); + printf(" %s" , service_state($s->{'has_been_checked'}, $s->{'current_state'})); + + if ($v >= 2) { + printf(" %d/%d", $s->{'current_attempt'}, $s->{'max_attempts'}); } + + printf(" %s\n", $s->{'plugin_output'}); } sub display_host_services { @@ -224,17 +215,20 @@ sub display_host_services { sub display_host_single { my ($host) = @_; my $h = $data->{hosts}->{$host}; + my $v = $verbosity; if ($short and not $h->{current_state}) { return; } - printf( - "%-32.32s %s %s\n", - $h->{host_name}, - host_state($h->{has_been_checked}, $h->{current_state}), - $h->{plugin_output}, - ); + printf("%-32.32s", $h->{'host_name'}); + printf(" %s", host_state($h->{'has_been_checked'}, $h->{'current_state'})); + + if ($v >= 2) { + printf(" %d/%d", $h->{'current_attempt'}, $h->{'max_attempts'}); + } + + printf(" %s\n", $h->{'plugin_output'}); } sub display_host { diff --git a/t/50-icli.t b/t/50-icli.t index 29702ab..1c9e344 100644 --- a/t/50-icli.t +++ b/t/50-icli.t @@ -118,10 +118,10 @@ $icli = "bin/icli -f t/in/status.dat.weird.2 -c t/in/objects.cache"; $cmd = Test::Command->new(cmd => "$icli -lh -h alpha"); $cmd->exit_isnt_num(0); -$cmd->stdout_is_eq($EMPTY); +$cmd->stdout_is_eq('alpha '); $cmd->stderr_is_eq("Unknown host state: 23\n"); $cmd = Test::Command->new(cmd => "$icli -ls -h aneurysm"); $cmd->exit_isnt_num(0); -$cmd->stdout_is_eq($EMPTY); +$cmd->stdout_is_eq('Disk: / '); $cmd->stderr_is_eq("Unknown service state: 23\n"); |