Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Travel-Status-DE-HAFAS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
derf
Travel-Status-DE-HAFAS
Commits
ba17712a
Commit
ba17712a
authored
13 years ago
by
Birte Kristina Friesel
Browse files
Options
Downloads
Patches
Plain Diff
db-ris: Add --help and --version options
parent
044489b5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/db-ris
+48
-17
48 additions, 17 deletions
bin/db-ris
with
48 additions
and
17 deletions
bin/db-ris
+
48
−
17
View file @
ba17712a
...
...
@@ -5,7 +5,7 @@ use 5.010;
our
$VERSION
=
'
0.0
';
use
Getopt::
Long
;
use
Getopt::
Long
qw(:config no_ignore_case)
;
use
List::
Util
qw(first max)
;
use
Travel::Status::DE::
DeutscheBahn
;
...
...
@@ -18,11 +18,14 @@ my @output;
binmode
(
STDOUT
,
'
:encoding(utf-8)
'
);
GetOptions
(
'
d|date=s
'
=>
\
$date
,
'
v|via=s
'
=>
\
$filter_via
,
'
m|mot=s
'
=>
\
$types
,
'
t|time=s
'
=>
\
$time
,
);
'
d|date=s
'
=>
\
$date
,
'
h|help
'
=>
sub
{
show_help
(
0
)
},
'
m|mot=s
'
=>
\
$types
,
'
t|time=s
'
=>
\
$time
,
'
v|via=s
'
=>
\
$filter_via
,
'
V|version
'
=>
\
&show_version
,
)
or
show_help
(
1
);
for
my
$type
(
split
(
qr{,}
,
$types
)
)
{
if
(
substr
(
$type
,
0
,
1
)
eq
q{!}
)
{
...
...
@@ -40,6 +43,22 @@ my $status = Travel::Status::DE::DeutscheBahn->new(
time
=>
$time
,
);
sub
show_help
{
my
(
$code
)
=
@_
;
print
'
Usage: db-ris [-d <dd.mm.yyyy>] [-m <motlist>] [-t <time>]
'
.
"
[-v <via>] <station>
\n
"
.
"
See also: man db-ris
\n
";
exit
$code
;
}
sub
show_version
{
say
"
db-ris version
${VERSION}
";
exit
0
;
}
sub
display_result
{
my
(
@lines
)
=
@_
;
...
...
@@ -61,22 +80,17 @@ sub display_result {
return
;
}
for
my
$d
(
$status
->
results
()
)
{
my
(
@via
,
@via_main
,
@via_show
);
sub
filter_via
{
my
(
@via
)
=
@_
;
@via
=
$d
->
route
;
if
(
$filter_via
and
not
(
first
{
$_
=~
m{$filter_via}io
}
@via
)
)
{
next
;
}
my
(
@via_main
,
@via_show
,
$last_stop
);
for
my
$stop
(
@via
)
{
if
(
$stop
=~
m{ ?Hbf}
)
{
push
(
@via_main
,
$stop
);
}
}
pop
(
@via
);
$last_stop
=
pop
(
@via
);
if
(
@via_main
and
@via
and
$via
[
0
]
eq
$via_main
[
0
]
)
{
shift
(
@via_main
);
...
...
@@ -90,7 +104,7 @@ for my $d ( $status->results() ) {
while
(
@via_show
<
3
and
@via_main
)
{
my
$stop
=
shift
(
@via_main
);
if
(
$stop
~~
\
@via_show
or
$stop
eq
$
d
->
destination
)
{
if
(
$stop
~~
\
@via_show
or
$stop
eq
$
last_stop
)
{
next
;
}
push
(
@via_show
,
$stop
);
...
...
@@ -101,11 +115,24 @@ for my $d ( $status->results() ) {
$stop
=~
s{ ?Hbf}{}
;
}
return
@via_show
;
}
for
my
$d
(
$status
->
results
()
)
{
my
(
@via
,
@via_main
,
@via_show
);
@via
=
$d
->
route
;
if
(
$filter_via
and
not
(
first
{
$_
=~
m{$filter_via}io
}
@via
)
)
{
next
;
}
push
(
@output
,
[
$d
->
time
,
$d
->
train
,
join
(
q{ }
,
@via_show
),
$d
->
destination
,
join
(
q{ }
,
filter_via
(
@via
)
),
$d
->
destination
,
$d
->
platform
,
$d
->
info
]
);
...
...
@@ -176,6 +203,10 @@ destination) matches the perl regular expression I<regex>. The match is not
case-sensitive. Use '^regex$' to match a full string, but be aware that this
may not work as expected.
=item B<-V>, B<--version>
Show version information
=back
=head1 EXIT STATUS
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment