Mercurial > hg > lxmldump
comparison lxmldump.py @ 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 |
comparison
equal
deleted
inserted
replaced
21:7ef08e05a5bf | 22:76856fc4e5fa |
---|---|
63 sys.stderr.close() | 63 sys.stderr.close() |
64 | 64 |
65 | 65 |
66 ## Print string with indentation | 66 ## Print string with indentation |
67 def pkk_printi(indent, smsg): | 67 def pkk_printi(indent, smsg): |
68 pkk_print((" " * indent) + smsg) | 68 pkk_print((" " * pkk_cfg.indent * indent) + smsg) |
69 | 69 |
70 | 70 |
71 ## Check value against current verbosity level | 71 ## Check value against current verbosity level |
72 def pkk_verbosity(lvl): | 72 def pkk_verbosity(lvl): |
73 return pkk_cfg.verbosity >= lvl | 73 return pkk_cfg.verbosity >= lvl |
216 description="lxmldump - Dump ISO/FDIS 1951 XML file data", | 216 description="lxmldump - Dump ISO/FDIS 1951 XML file data", |
217 usage="%(prog)s [options] <input xml file(s)>", | 217 usage="%(prog)s [options] <input xml file(s)>", |
218 epilog="\n\n" | 218 epilog="\n\n" |
219 ) | 219 ) |
220 | 220 |
221 optparser.add_argument("filenames", action="extend", nargs="*", | 221 optparser.add_argument("filenames", |
222 type=str, metavar="filename", help="XML filename(s)") | 222 type=str, action="extend", nargs="*", |
223 metavar="filename", | |
224 help="XML filename(s)") | |
223 | 225 |
224 optparser.add_argument("-d", "--dump", | 226 optparser.add_argument("-d", "--dump", |
227 dest="mode", | |
225 action="store_const", const=PKK_MODE_DUMP, default=PKK_MODE_NORMAL, | 228 action="store_const", const=PKK_MODE_DUMP, default=PKK_MODE_NORMAL, |
226 dest="mode", help="output as simple dump") | 229 help="output as simple dump") |
227 | 230 |
228 optparser.add_argument("-x", "--xml", | 231 optparser.add_argument("-x", "--xml", |
232 dest="mode", | |
229 action="store_const", const=PKK_MODE_XML, | 233 action="store_const", const=PKK_MODE_XML, |
230 dest="mode", help="output as XML") | 234 help="output as XML") |
231 | 235 |
232 optparser.add_argument("-n", "--normalize", | 236 optparser.add_argument("-n", "--normalize", |
237 dest="normalize", | |
233 action="store_const", const=True, default=False, | 238 action="store_const", const=True, default=False, |
234 dest="normalize", help="output NFC normalized Unicode") | 239 help="output NFC normalized Unicode") |
235 | 240 |
236 optparser.add_argument("-a", "--annotate", | 241 optparser.add_argument("-a", "--annotate", |
242 dest="annotate", | |
237 action="store_const", const=True, default=False, | 243 action="store_const", const=True, default=False, |
238 dest="annotate", help="annotate strings") | 244 help="annotate strings") |
239 | 245 |
240 optparser.add_argument("-v", "--verbosity", | 246 optparser.add_argument("-v", "--verbosity", |
241 type=int, choices=range(0,4), default=3, | 247 dest="verbosity", |
248 type=int, choices=range(0, 4), default=3, | |
242 metavar="n", | 249 metavar="n", |
243 dest="verbosity", help='set verbosity level (0-3, default: %(default)s)') | 250 help='set verbosity level (0-3, default: %(default)s)') |
244 | 251 |
245 optparser.add_argument("-p", "--debug", | 252 optparser.add_argument("-p", "--debug", |
246 action="store_const", const=True, default=False, | 253 dest="debug", action="store_const", const=True, default=False, |
247 dest="debug", help=argparse.SUPPRESS) | 254 help=argparse.SUPPRESS) |
255 | |
256 optparser.add_argument("-i", "--indent", | |
257 dest="indent", | |
258 type=int, choices=range(0, 32), default=4, | |
259 metavar="n", | |
260 help='indent output by <n> characters (default: %(default)s)') | |
248 | 261 |
249 | 262 |
250 ### Show help if needed | 263 ### Show help if needed |
251 pkk_cfg = optparser.parse_args() | 264 pkk_cfg = optparser.parse_args() |
252 if len(pkk_cfg.filenames) == 0: | 265 if len(pkk_cfg.filenames) == 0: |