Fix output of dns-list-zones and dns-zone-list

This commit is contained in:
2025-09-01 16:58:14 +02:00
parent d163a82e0e
commit fd33964168
2 changed files with 17 additions and 10 deletions

View File

@@ -14,7 +14,7 @@ def main():
prog, max_help_position=45, width=140))
parser.add_argument('-a', '--all-zones', help='do not ignore zones that are not managed', action='store_true')
parser.add_argument('-c', '--config', help='path to config file', default=dnsmgr.DEFAULT_CFGFILE)
parser.add_argument('-d', '--decode', help='decode internationalized domain names (IDN)', action='store_true')
output = parser.add_mutually_exclusive_group()
output.add_argument('-j', '--json', help='print json format', action='store_true')
output.add_argument('-J', '--json-pretty', help='print pretty json format', action='store_true')
@@ -33,16 +33,16 @@ def main():
dnsmgr.printe(e)
sys.exit(150)
zones.sort(key=lambda z: z.origin.to_text())
zones.sort(key=lambda zone: zone.origin.to_unicode() if args.decode else zone.origin.to_text())
if args.raw:
for zone in zones:
name = zone.origin.to_text()
name = zone.origin.to_unicode(True) if args.decode else zone.origin.to_text(True)
managed = zone.cfgfile is not None
print(f'{name}\t{zone.view}\t{zone.status}\t{managed}')
elif args.json or args.json_pretty:
json_output = [{
'zone': zone.origin.to_text(),
'zone': zone.origin.to_unicode(True) if args.decode else zone.origin.to_text(True),
'view': zone.view,
'status': zone.status,
'managed': zone.cfgfile is not None} for zone in zones]
@@ -58,7 +58,7 @@ def main():
rows = []
for zone in zones:
name = zone.origin.to_unicode(omit_final_dot=True)
name = zone.origin.to_unicode(True) if args.decode else zone.origin.to_text(True)
row = [name, zone.view, zone.status]
if args.all_zones:
row.append(zone.cfgfile is not None)