Support single dash for STDIN
Change-Id: Idaa8ab3632f5787b06193892b583763276ea0fb8
diff --git a/script/tei2korapxml b/script/tei2korapxml
index 0d196a5..6f3ad1f 100755
--- a/script/tei2korapxml
+++ b/script/tei2korapxml
@@ -29,7 +29,7 @@
1;
};
-our $VERSION = '2.2.0';
+our $VERSION = '2.3.0';
our $VERSION_MSG = "\ntei2korapxml - v$VERSION\n";
@@ -64,6 +64,7 @@
'header-file=s' => \(my $header_file = 'header'),
'tokens-file=s' => \(my $tokens_file = 'tokens'),
'log|l=s' => \(my $log_level = 'notice'),
+ '' => \(my $stdio),
'help|h' => sub {
pod2usage(
-verbose => 99,
@@ -161,12 +162,29 @@
# Input file handle (default: stdin)
-my $input_fh = *STDIN;
+my $input_fh;
-if ($input_fname ne '') {
+# Single dash was set
+if ($stdio) {
+ $input_fh = *STDIN;
+}
+
+# Input flag was passed
+elsif ($input_fname ne '') {
unless (open($input_fh, '<', $input_fname)) {
die $log->fatal("File '$input_fname' could not be opened.");
};
+}
+
+# No input to process
+else {
+ pod2usage(
+ -verbose => 99,
+ -sections => 'NAME|SYNOPSIS',
+ -msg => $VERSION_MSG,
+ -output => '-'
+ );
+ exit;
};
# Prevents segfaulting (see notes on segfault prevention)
@@ -408,7 +426,7 @@
=head1 SYNOPSIS
- cat corpus.i5.xml | tei2korapxml > corpus.korapxml.zip
+ cat corpus.i5.xml | tei2korapxml - > corpus.korapxml.zip
=head1 DESCRIPTION
@@ -416,9 +434,6 @@
L<I5|https://www.ids-mannheim.de/digspra/kl/projekte/korpora/textmodell>
based documents to the
L<KorAP-XML format|https://github.com/KorAP/KorAP-XML-Krill#about-korap-xml>.
-If no specific input is defined, data is
-read from C<STDIN>. If no specific output is defined, data is written
-to C<STDOUT>.
This program is usually called from inside another script.
@@ -490,6 +505,12 @@
=over 2
+=item B<--input|-i>
+
+The input file to process. If no specific input is defined and a single
+dash C<-> is passed as an argument, data is read from C<STDIN>.
+
+
=item B<--root|-r>
The root directory for output. Defaults to C<.>.