From 7b5b6c7ad849a6a2f68df8ac1b717effeebae9bd Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 14 Jul 2011 14:25:31 +0200 Subject: db-fakedisplay: Add --template switch --- bin/db-fakedisplay | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'bin/db-fakedisplay') diff --git a/bin/db-fakedisplay b/bin/db-fakedisplay index 1794b83..7724473 100755 --- a/bin/db-fakedisplay +++ b/bin/db-fakedisplay @@ -12,18 +12,14 @@ use Travel::Status::DE::DeutscheBahn; our $VERSION = '0.00'; -sub show_help { - my ($exit_status) = @_; - - say 'Usage: db-fakedisplay '; - say 'See also: man db-fakedisplay'; - - exit $exit_status; -} +my ($station, @platforms); +my $template_file; +my $template; GetOptions( 'h|help' => sub { show_help(0) }, + 't|template=s' => \&handle_template, 'V|version' => sub { say "db-fakedisplay version ${VERSION}"; exit 0 }, ) or show_help(1); @@ -32,9 +28,9 @@ if (@ARGV < 2) { show_help(1); } -my ($station, @platforms) = @ARGV; -my $template_file = dist_file('db-fakedisplay', 'template.html'); -my $template = HTML::Template->new( filename => $template_file); +($station, @platforms) = @ARGV; +$template_file //= dist_file('db-fakedisplay', 'single-lcd.html'); +$template = HTML::Template->new( filename => $template_file); my $status = Travel::Status::DE::DeutscheBahn->new( station => $station @@ -42,6 +38,29 @@ my $status = Travel::Status::DE::DeutscheBahn->new( my @params; +sub handle_template { + my (undef, $template_name) = @_; + + if (-e $template_name) { + $template_file = $template_name; + } + else { + $template_file = dist_file('db-fakedisplay', + $template_name); + } + + return; +} + +sub show_help { + my ($exit_status) = @_; + + say 'Usage: db-fakedisplay [-t template] '; + say 'See also: man db-fakedisplay'; + + exit $exit_status; +} + for my $platform (@platforms) { my $info = first { $_->platform =~ m{ ^ $platform (?: \s | $ )}x } $status->results; @@ -92,9 +111,15 @@ installed on most (major) stations. =over +=item B<-t>, B<--template> B|I + +Select template. Specify either a I or one of the templates shipped +with B (right now only B is available, which +is also the default). + =item B<-V>, B<--version> -Show version information +Show version information. =back -- cgit v1.2.3