summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2015-09-11 19:52:11 +0200
committerDaniel Friesel <derf@finalrewind.org>2015-09-11 19:52:11 +0200
commitae8462fc983013bf27358a0d4a17cca73b8cb1e7 (patch)
tree0e8452a1b56b7758caeffdb0284cd95d809b96c6 /bin
parentde432ead84057a6f9234cbcb56004d625333a7bd (diff)
exclusive _and_ inclusive mots \o/
Diffstat (limited to 'bin')
-rwxr-xr-xbin/hafas-m50
1 files changed, 28 insertions, 22 deletions
diff --git a/bin/hafas-m b/bin/hafas-m
index dc053c9..33a4d9f 100755
--- a/bin/hafas-m
+++ b/bin/hafas-m
@@ -10,8 +10,6 @@ use List::MoreUtils qw(uniq);
use List::Util qw(first max);
use Travel::Status::DE::HAFAS;
-my %train_type;
-
my ( $date, $time );
my $arrivals = 0;
my $ignore_late = 0;
@@ -19,7 +17,7 @@ my $types = q{};
my $language;
my $developer_mode;
my ( $list_services, $service, $hafas_url );
-my @excluded_mots;
+my ( @excluded_mots, @exclusive_mots );
my @output;
@@ -49,30 +47,13 @@ if ($list_services) {
exit 0;
}
-for my $type ( split( qr{,}, $types ) ) {
- if ( substr( $type, 0, 1 ) eq q{!} ) {
- $train_type{ substr( $type, 1 ) } = 0;
- push( @excluded_mots, substr( $type, 1 ) );
- }
- else {
- $train_type{$type} = 1;
- }
-}
-
-if ( $train_type{help} or $train_type{list} or $train_type{'?'} ) {
- 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;
-}
+parse_mot_options();
my $status = Travel::Status::DE::HAFAS->new(
date => $date,
language => $language,
excluded_mots => \@excluded_mots,
+ exclusive_mots => \@exclusive_mots,
station => shift || show_help(1),
time => $time,
mode => $arrivals ? 'arr' : 'dep',
@@ -97,6 +78,31 @@ sub show_version {
exit 0;
}
+sub parse_mot_options {
+
+ my $default_yes = 1;
+ my $help;
+
+ 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;
+ }
+ elsif ( substr( $type, 0, 1 ) eq q{!} ) {
+ push( @excluded_mots, substr( $type, 1 ) );
+ }
+ else {
+ push( @exclusive_mots, $type );
+ }
+ }
+}
+
sub display_result {
my (@lines) = @_;