changeset 97:2b880f2ce894

basic help format hacking works
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Fri, 16 Apr 2021 12:55:05 +0000
parents a7e72a254790
children 1a4c5fdc2923
files bin/ix.py
diffstat 1 files changed, 28 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/bin/ix.py	Fri Apr 16 09:01:16 2021 +0000
+++ b/bin/ix.py	Fri Apr 16 12:55:05 2021 +0000
@@ -7,24 +7,31 @@
 
 Note that if no output flag(s) is/are given, the whole WARC record will be output, more efficiently than would be the case if all three flags were given.'''
 
-import argparse 
+import sys, argparse, regex
+
+HACK=regex.compile('\[-x\]\n\s*\[length\] \[offset\] \[filename\]')
 
+class HackFormat(argparse.RawDescriptionHelpFormatter):
+  def format_help(self):
+    global FOO
+    FOO=argparse.RawDescriptionHelpFormatter.format_help(self)
+    return HACK.sub('\n             [ ( -x | length offset filename ) ]',
+                        FOO)
+  
 parser = argparse.ArgumentParser(
   description='''Extract records from warc files given length, offset and file triples.
 Input one triple on command line, or
 triples from stdin as tab-delimited lines
 or complete cdx index lines.''',
-  epilog='''[ -x | length option file]
-
-Note that if no output flag(s) is/are given,
+  epilog='''Note that if no output flag(s) is/are given,
 the whole WARC record will be output, more efficiently than
 would be the case if all three flags were given.''',
   add_help=False,
   conflict_handler='resolve',
-  formatter_class=argparse.RawDescriptionHelpFormatter
+  formatter_class=HackFormat
   )
   
-parser.add_argument('--help',help='Show help',action='store_true')
+parser.add_argument('--help',help='Show help',action='help')
 parser.add_argument('-d','--debug',help='Debug output',action='store_true')
 parser.add_argument('-w','--warc',help='output WARC headers',
                     action='store_true')
@@ -32,17 +39,23 @@
                     action='store_true')
 parser.add_argument('-b','--body',help='output HTTP body',
                     action='store_true')
-parser.add_argument('-e','--exec',help='pipes each result thru EXEC')
+parser.add_argument('-c','--cmd',help='pipes each result thru CMD')
 sg=parser.add_mutually_exclusive_group()
 sg.add_argument('-x','--index',
                     help='take lines of triples from a cdx index file as input',
                     action='store_true')
-tg=sg.add_argument_group('triple','explicit triple')
-tg.add_argument('length',type=int,
-                    help='length in bytes of gzipped record')
-tg.add_argument('offset',type=int,
-                    help='start position in bytes of gzipped record')
-tg.add_argument('filename',
-                    help='name of gzipped Common Crawl WARC-format file')
+sg.add_argument('length',type=int,
+                help='length in bytes of gzipped record',
+                nargs='?')
+parser.add_argument('offset',type=int,
+                    help='start position in bytes of gzipped record',
+                    nargs='?')
+parser.add_argument('filename',
+                    help='name of gzipped Common Crawl WARC-format file',
+                    nargs='?')
 
-parser.print_help()
+#parser.print_help()
+pa=parser.parse_args(sys.argv[1:])
+# We have to enforce our own check..
+print(pa)
+