From f025a2f107bb389b2dbd50ef4e4d4ff912d993a1 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 14 Sep 2015 18:06:19 +0200 Subject: hafas-m documentation and -m help error handling --- bin/hafas-m | 44 ++++++++++++++++++++++++++++++++----------- lib/Travel/Status/DE/HAFAS.pm | 7 ++++--- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/bin/hafas-m b/bin/hafas-m index 72c7560..3a1458b 100755 --- a/bin/hafas-m +++ b/bin/hafas-m @@ -85,14 +85,19 @@ sub parse_mot_options { for my $type ( split( qr{,}, $types ) ) { if ( $type eq 'help' or $type eq 'list' or $type eq '?' ) { - my @mots - = @{ Travel::Status::DE::HAFAS::get_service($service) - ->{productbits} }; - @mots = grep { $_ ne 'x' } @mots; - @mots = uniq @mots; - @mots = sort @mots; - say join( "\n", @mots ); - exit 0; + my $desc = Travel::Status::DE::HAFAS::get_service($service); + if ($desc) { + my @mots = @{ $desc->{productbits} }; + @mots = grep { $_ ne 'x' } @mots; + @mots = uniq @mots; + @mots = sort @mots; + say join( "\n", @mots ); + exit 0; + } + else { + say STDERR 'no modes of transport known for this service'; + exit 1; + } } elsif ( substr( $type, 0, 1 ) eq q{!} ) { push( @excluded_mots, substr( $type, 1 ) ); @@ -213,8 +218,7 @@ departure screens installed at most main stations. Show arrivals instead of departures, including trains ending at the specified station. Note that this causes the output to display the start instead of -the end station and B<-f> to list all stops between start end -I, not I and end. +the end station. =item B<-d>, B<--date> I
.I.I @@ -223,12 +227,16 @@ Date to list departures for. Default: today. =item B<-l>, B<--lang> B|B|B|B Set language used for additional information. Supports Beutsch (default), -Bnglish, Btalian and dutch (B). +Bnglish, Btalian and dutch (B), depending on the used service. =item B<-L>, B<--ignore-late> Do not display delayed trains. +=item B<--list> + +List known HAFAS installations. See also B<--service> and B<--url>. + =item B<-m>, B<--mot> I By default, B shows all modes of transport arriving/departing at the @@ -241,10 +249,24 @@ To show them exclusively, set I to I,I,... The I types depend on the used service. Use C<< -m help >> to list them. +=item B<-s>, B<--service> I + +Request arrivals/departures using the API provided by I, defaults +to DB (Deutsche Bahn). See B<--list> for a list of known services. + =item B<-t>, B<--time> I:I Time to list departures for. Default: now. +=item B<-u>, B<--url> I + +Request arrivals/departures using the API entry point at I, defaults to +C<< http://reiseauskunft.bahn.de/bin/bhftafel.exe >>. Note that the language +and output selection suffix (e.g. "/dn") must not be included here. + +Again, see B<--list> for a list of known URLs. Unknown URLs are also +supported, though note that B<--mot> will not work when using this opton. + =item B<-V>, B<--version> Show version information. diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index 2a7bb11..8d33ec9 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -333,9 +333,10 @@ sub get_services { sub get_service { my ($service) = @_; - $service //= 'DB'; - - return $hafas_instance{$service}; + if ( defined $service ) { + return $hafas_instance{$service}; + } + return; } sub get_active_service { -- cgit v1.2.3