# HG changeset patch # User Matti Hamalainen # Date 1639038710 -7200 # Node ID 0849d65fabce8f1e6493976bd8ac35ad6d78c7c0 # Parent 8481f8f52a84956a8c00aeef666fc7b60e57dd26 More work on improving help. diff -r 8481f8f52a84 -r 0849d65fabce lxmldump.py --- a/lxmldump.py Thu Dec 09 10:11:26 2021 +0200 +++ b/lxmldump.py Thu Dec 09 10:31:50 2021 +0200 @@ -487,7 +487,6 @@ print(u"\nAvailable output modes:") print(" " + ", ".join(pkk_modes_list.values())) - def error(self, message): self.print_help() sys.stderr.write(f"\nerror: {message}\n") @@ -500,7 +499,7 @@ ) optparser.add_argument("filenames", - type=str, action="extend", nargs="+", + type=str, action="extend", nargs="*", metavar="filename", help="XML filename(s)") @@ -555,16 +554,24 @@ pkk_cfg = optparser.parse_args() if pkk_cfg.list_values: + print(u"\nAvailable output modes:") + print(" " + ", ".join(pkk_modes_list.values())) + if pkk_cfg.mode not in [PKK_MODE_NORMAL, PKK_MODE_ANKI]: pkk_cfg.mode = PKK_MODE_NORMAL - print(u"Available format strings and values (mode '{}'):".format( + print(u"\nAvailable format strings and values (mode '{}'):".format( pkk_modes_list[pkk_cfg.mode])) for mid in pkk_mode_defaults: stmp = pkk_get_value(mid).replace("\\", "\\\\").replace("\n", "\\n") print(u" {:22s} : '{}'".format(mid, stmp)) + sys.exit(0) + + elif len(pkk_cfg.filenames) == 0: + optparser.print_help() + ### Handle each input file for filename in pkk_cfg.filenames: # Parse XML file into element tree