mbj4668 / rfcstrip

Extracts code components, YANG modules and SMIv2 modules from RFCs and Internet Drafts
Other
10 stars 7 forks source link

Extracting from STDIN does not work #3

Closed auerswal closed 4 years ago

auerswal commented 4 years ago

The code tries to handle reading from STDIN by using - instead of a file name. This does not work in my tests on Ubuntu GNU/Linux 18.04 LTS:

$ ./rfcstrip -n rfc8650.xml 
ietf-restconf-subscribed-notifications@2019-11-17.yang: 85 lines.
ex-subscription-completed.json: 8 lines.
ex-subscription-terminated.json: 9 lines.
$ ./rfcstrip -n < /tmp/mozilla_auerswald0/rfc8650.xml 
$ cat rfc8650.xml | ./rfcstrip -n
$

The usage output actually requires a file argument. A minimal patch to require a file argumet in the code as well would be:

diff --git a/rfcstrip b/rfcstrip
index befe4ab..5f64e3f 100755
--- a/rfcstrip
+++ b/rfcstrip
@@ -439,7 +439,8 @@ done
 shift `expr $OPTIND - 1`

 if [ $# -eq 0 ] ; then
-    do_strip -
+    do_usage
+    exit 1
 else
     for f in "$@" ; do
         do_strip "$f"
wlupton commented 4 years ago

@mbj4668 I'd love it if the tool could read from stdin. I see that this earlier fix was to remove any claim to support it, but would you consider a patch to restore stdin support? Probably (like the old rfcstrip) stdin would be used implicitly if no files are supplied, and also permitted via an explicit "-".

mbj4668 commented 4 years ago

Sure, a PR that adds this support is welcome! The current code opens the input file twice; it first uses head -n 1 in order to guess the input format, and then parses the entire file (text or xml). So this needs to be changed.