From f96d7c7f0edd3a9b2fd928af452f300559b87266 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 21 Nov 2011 10:49:25 +0100 Subject: efa-m: Add --linelist option (list all available lines) --- bin/efa-m | 71 +++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/bin/efa-m b/bin/efa-m index 66694c6..dfa6ef7 100755 --- a/bin/efa-m +++ b/bin/efa-m @@ -11,14 +11,14 @@ use Getopt::Long qw(:config no_ignore_case); use List::Util qw(max); use Travel::Status::DE::VRR; -my ( $date, $time, $input_type ); +my ( $date, $time, $input_type, $list_lines ); my ( @grep_lines, @grep_platforms ); -my @output; GetOptions( 'd|date=s' => \$date, 'h|help' => sub { show_help(0) }, 'l|line=s@' => \@grep_lines, + 'L|linelist' => \$list_lines, 'p|platform=s@' => \@grep_platforms, 't|time=s' => \$time, 'V|version' => \&show_version, @@ -98,33 +98,64 @@ sub display_result { return; } -if ( my $err = $status->errstr ) { - say STDERR "Request error: ${err}"; - exit 2; -} +sub show_lines { + my @output; -for my $d ( $status->results ) { + for my $l ( $status->lines ) { - my $platform = $d->platform; + if ( @grep_lines and not( $l->name ~~ \@grep_lines ) ) { + next; + } - if ( $d->platform_db ) { - $platform .= ' (DB)'; + push( @output, + [ $l->type, $l->name, $l->direction // q{}, $l->route // q{} ] ); } - if ( - ( @grep_lines and not( $d->line ~~ \@grep_lines ) ) - or ( @grep_platforms - and not( $platform ~~ \@grep_platforms ) ) - ) - { - next; + display_result(@output); + + return; +} + +sub show_results { + my @output; + + for my $d ( $status->results ) { + + my $platform = $d->platform; + + if ( $d->platform_db ) { + $platform .= ' (DB)'; + } + + if ( + ( @grep_lines and not( $d->line ~~ \@grep_lines ) ) + or ( @grep_platforms + and not( $platform ~~ \@grep_platforms ) ) + ) + { + next; + } + + push( @output, + [ $d->time, $platform, $d->line, $d->destination, $d->info ] ); } - push( @output, - [ $d->time, $platform, $d->line, $d->destination, $d->info ] ); + display_result(@output); + + return; +} + +if ( my $err = $status->errstr ) { + say STDERR "Request error: ${err}"; + exit 2; } -display_result(@output); +if ($list_lines) { + show_lines(); +} +else { + show_results(); +} __END__ -- cgit v1.2.3