changeset 22:76856fc4e5fa

Clean up argument handling.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 16 May 2021 16:10:44 +0300
parents 7ef08e05a5bf
children 3ef1c5463b8f
files lxmldump.py
diffstat 1 files changed, 24 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lxmldump.py	Tue May 11 18:37:53 2021 +0300
+++ b/lxmldump.py	Sun May 16 16:10:44 2021 +0300
@@ -65,7 +65,7 @@
 
 ## Print string with indentation
 def pkk_printi(indent, smsg):
-    pkk_print(("    " * indent) + smsg)
+    pkk_print((" " * pkk_cfg.indent * indent) + smsg)
 
 
 ## Check value against current verbosity level
@@ -218,33 +218,46 @@
     epilog="\n\n"
     )
 
-optparser.add_argument("filenames", action="extend", nargs="*",
-    type=str, metavar="filename", help="XML filename(s)")
+optparser.add_argument("filenames",
+    type=str, action="extend", nargs="*",
+    metavar="filename",
+    help="XML filename(s)")
 
 optparser.add_argument("-d", "--dump",
+    dest="mode",
     action="store_const", const=PKK_MODE_DUMP, default=PKK_MODE_NORMAL,
-    dest="mode", help="output as simple dump")
+    help="output as simple dump")
 
 optparser.add_argument("-x", "--xml",
+    dest="mode",
     action="store_const", const=PKK_MODE_XML,
-    dest="mode", help="output as XML")
+    help="output as XML")
 
 optparser.add_argument("-n", "--normalize",
+    dest="normalize",
     action="store_const", const=True, default=False,
-    dest="normalize", help="output NFC normalized Unicode")
+    help="output NFC normalized Unicode")
 
 optparser.add_argument("-a", "--annotate",
+    dest="annotate",
     action="store_const", const=True, default=False,
-    dest="annotate", help="annotate strings")
+    help="annotate strings")
 
 optparser.add_argument("-v", "--verbosity",
-    type=int, choices=range(0,4), default=3,
+    dest="verbosity",
+    type=int, choices=range(0, 4), default=3,
     metavar="n",
-    dest="verbosity", help='set verbosity level (0-3, default: %(default)s)')
+    help='set verbosity level (0-3, default: %(default)s)')
 
 optparser.add_argument("-p", "--debug",
-    action="store_const", const=True, default=False,
-    dest="debug", help=argparse.SUPPRESS)
+    dest="debug", action="store_const", const=True, default=False,
+    help=argparse.SUPPRESS)
+
+optparser.add_argument("-i", "--indent",
+    dest="indent",
+    type=int, choices=range(0, 32), default=4,
+    metavar="n",
+    help='indent output by <n> characters (default: %(default)s)')
 
 
 ### Show help if needed