diff docs/test2rst.py @ 5664:1d80cda7fe93 stable

test2rst: minor improvements
author Anton Shestakov <av6@dwimlabs.net>
date Mon, 23 Nov 2020 13:43:29 +0800
parents 9d6c3e227455
children
line wrap: on
line diff
--- a/docs/test2rst.py	Wed Nov 11 18:34:15 2020 +0800
+++ b/docs/test2rst.py	Mon Nov 23 13:43:29 2020 +0800
@@ -1,8 +1,8 @@
 #!/usr/bin/env python3
 
+import argparse
 import os
 import re
-import sys
 
 
 ignored_patterns = [
@@ -14,6 +14,7 @@
 
 
 def rstify(orig):
+    """Take contents of a .t file and produce reStructuredText"""
     newlines = []
 
     code_block_mode = False
@@ -21,7 +22,7 @@
 
     for line in orig.splitlines():
 
-        # Emtpy lines doesn't change output
+        # Empty lines doesn't change output
         if not line:
             newlines.append(line)
             code_block_mode = False
@@ -59,17 +60,19 @@
     return "\n".join(newlines)
 
 
-def main(path):
-    with open(path) as f:
+def main():
+    ap = argparse.ArgumentParser()
+    ap.add_argument('testfile', help='.t file to transform')
+
+    opts = ap.parse_args()
+
+    with open(opts.testfile) as f:
         content = f.read()
     rst = rstify(content)
-    target = os.path.splitext(path)[0] + '.rst'
+    target = os.path.splitext(opts.testfile)[0] + '.rst'
     with open(target, 'w') as f:
         f.write(rst)
 
 
 if __name__ == '__main__':
-    if len(sys.argv) != 2:
-        print('Please supply a path to tests dir as parameter')
-        sys.exit()
-    main(sys.argv[1])
+    main()