summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-11-21 10:49:25 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-11-21 10:49:25 +0100
commitf96d7c7f0edd3a9b2fd928af452f300559b87266 (patch)
treeeeead8c6dbf399206215a533deb03bfc6d56fb06
parent96c0158b7acada5ade93743e1286e35eed33a3cf (diff)
efa-m: Add --linelist option (list all available lines)
-rwxr-xr-xbin/efa-m71
1 files 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__