From 20e896f5b73c9bc4cc40ef9bf0428a4d17cf1ee8 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sat, 11 Nov 2023 08:35:31 +0100 Subject: show messages depending on selected verbosity --- bin/hafas | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/bin/hafas b/bin/hafas index b36b337..cd3fe5a 100755 --- a/bin/hafas +++ b/bin/hafas @@ -21,8 +21,18 @@ my $developer_mode; my $json_output; my ( $list_services, $service ); my ( @excluded_mots, @exclusive_mots ); +my $verbosity = 0; my @output; +my %min_verbosity = ( + A => 3, + C => 1, + G => 2, + H => 1, + L => 0, + M => 1, + P => 0, +); binmode( STDOUT, ':encoding(utf-8)' ); for my $arg (@ARGV) { @@ -36,6 +46,7 @@ GetOptions( 'm|mot=s' => \$types, 's|service=s' => \$service, 't|time=s' => \$time, + 'v|verbose+' => \$verbosity, 'V|version' => \&show_version, 'devmode' => \$developer_mode, 'json' => \$json_output, @@ -233,6 +244,18 @@ sub format_delay { return q{}; } +sub show_message { + my ($msg) = @_; + if ( $verbosity >= ( $min_verbosity{ $msg->type } // 0 ) ) { + if ( $msg->short ) { + printf( "| %s\n", $msg->short ); + } + printf( "| %s\n", $msg->text ); + return 1; + } + return; +} + if ( my $err = $hafas->errstr ) { say STDERR "Request error: ${err}"; if ( $hafas->errcode @@ -277,10 +300,7 @@ for my $res ( @{ $hafas->{results} } ) { display_occupancies( $res->load ), $glance ); for my $msg ( $res->messages ) { - if ( $msg->short ) { - printf( "# %s\n", $msg->short ); - } - printf( "# %s\n", $msg->text ); + show_message($msg); } say q{}; @@ -322,10 +342,7 @@ for my $res ( @{ $hafas->{results} } ) { { next; } - if ( $msg->short ) { - printf( "# %s\n", $msg->short ); - } - printf( "# %s\n", $msg->text ); + show_message($msg); } say q{}; } -- cgit v1.2.3