diff options
author | Jan Doskočil <jan.doskocil@nic.cz> | 2024-11-26 18:00:18 +0100 |
---|---|---|
committer | Daniel Salzman <daniel.salzman@nic.cz> | 2024-11-29 18:03:37 +0100 |
commit | 83ac6a053921c9f821bfa645998441221b1bda1d (patch) | |
tree | 9f66ad08dbb4616a0a11ec338a98255105621a6c | |
parent | mod-rrl: change default log-period to 30 seconds (diff) | |
download | knot-83ac6a053921c9f821bfa645998441221b1bda1d.tar.xz knot-83ac6a053921c9f821bfa645998441221b1bda1d.zip |
knot-exporter: less confusing opt parsing and help
-rwxr-xr-x | python/knot_exporter/knot_exporter/knot_exporter.py | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/python/knot_exporter/knot_exporter/knot_exporter.py b/python/knot_exporter/knot_exporter/knot_exporter.py index 7d6fc3791..f3fb69639 100755 --- a/python/knot_exporter/knot_exporter/knot_exporter.py +++ b/python/knot_exporter/knot_exporter/knot_exporter.py @@ -154,9 +154,21 @@ class KnotCollector(object): yield val +class KnotHelpFormatter(argparse.HelpFormatter): + def _get_help_string(self, action): + help = action.help + if help is None: + help = '' + + if not (type(action.default) is bool or action.default in (None, argparse.SUPPRESS)): + help += argparse._(' (default: %(default)s)') + + return help + + def main(): parser = argparse.ArgumentParser( - formatter_class = argparse.ArgumentDefaultsHelpFormatter, + formatter_class = KnotHelpFormatter, ) parser.add_argument( @@ -193,60 +205,58 @@ def main(): parser.add_argument( "--no-meminfo", - action='store_false', + dest="meminfo", + action="store_false", help="disable collection of memory usage" ) parser.add_argument( "--no-global-stats", - action='store_false', + dest="global_stats", + action="store_false", help="disable collection of global statistics" ) parser.add_argument( "--no-zone-stats", - action='store_false', + dest="zone_stats", + action="store_false", help="disable collection of zone statistics" ) parser.add_argument( "--no-zone-status", - action='store_false', + dest="zone_status", + action="store_false", help="disable collection of zone status" ) parser.add_argument( "--no-zone-serial", - action='store_false', + dest="zone_serial", + action="store_false", help="disable collection of zone serial" ) parser.add_argument( "--zone-timers", - action='store_true', - default=False, + dest="zone_timers", + action="store_true", help="enable collection of zone SOA timer values" ) - parser.add_argument( - "--no-zone-timers", - action='store_const', - help="supported for compatibility reasons; no effect", - # deprecated=True # in python >=3.13 - ) - args = parser.parse_args() REGISTRY.register(KnotCollector( args.knot_library_path, args.knot_socket_path, args.knot_socket_timeout, - args.no_meminfo, - args.no_global_stats, - args.no_zone_stats, - args.no_zone_status, + args.meminfo, + args.global_stats, + args.zone_stats, + args.zone_status, args.zone_timers, - args.no_zone_serial, + args.zone_serial, )) class Server(http.server.HTTPServer): |