Commit f96d7c7f authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

efa-m: Add --linelist option (list all available lines)

parent 96c0158b
Loading
Loading
Loading
Loading
+51 −20
Original line number Diff line number Diff line
@@ -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,11 +98,27 @@ sub display_result {
	return;
}

if ( my $err = $status->errstr ) {
	say STDERR "Request error: ${err}";
	exit 2;
sub show_lines {
	my @output;

	for my $l ( $status->lines ) {

		if ( @grep_lines and not( $l->name ~~ \@grep_lines ) ) {
			next;
		}

		push( @output,
			[ $l->type, $l->name, $l->direction // q{}, $l->route // q{} ] );
	}

	display_result(@output);

	return;
}

sub show_results {
	my @output;

	for my $d ( $status->results ) {

		my $platform = $d->platform;
@@ -126,6 +142,21 @@ for my $d ( $status->results ) {

	display_result(@output);

	return;
}

if ( my $err = $status->errstr ) {
	say STDERR "Request error: ${err}";
	exit 2;
}

if ($list_lines) {
	show_lines();
}
else {
	show_results();
}

__END__

=head1 NAME