changeset 135:a76cc0df2754

add usage/help info
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Wed, 14 Jul 2021 16:50:30 +0000
parents d3ef00af2064
children f30a1b268cea
files bin/cdx2tsv.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/bin/cdx2tsv.py	Wed Jul 14 16:49:54 2021 +0000
+++ b/bin/cdx2tsv.py	Wed Jul 14 16:50:30 2021 +0000
@@ -10,6 +10,21 @@
    will output media type and URI scheme'''
 import json,sys
 
+if len(sys.argv)==1 or sys.argv[1][1]=='-':
+  print("""Reads index lines from stdin and extracts values from json dict part
+
+  Usage: cdx2tsv.py fieldspecs...
+
+  fieldspec is either a name or a quoted python tuple of a name and
+    an expression with free variable f which will be evaluated with f
+    having the field value.
+
+  For example 
+    cdx2tsv.py mime '(url,f.split(":",maxsplit=1)[0])' < xyzzy.cdx
+  will output media type and URI scheme""",
+        file=sys.stderr)
+  exit(1)
+
 fields=sys.argv[1:]
 
 fields=[((lambda x,y:(x,eval("lambda f:%s"%y)))(*(f[1:-1].split(',',maxsplit=1))) if f[0]=='(' else f) for f in fields]