diff --git a/src/ddns_service/cli.py b/src/ddns_service/cli.py index c8a928a..336433d 100644 --- a/src/ddns_service/cli.py +++ b/src/ddns_service/cli.py @@ -18,7 +18,7 @@ from .models import ( def cmd_user_list(args, app): """List all users.""" - users = User.select() + users = User.select().order_by(User.username) if not users: print("No users found.") return 0 @@ -144,13 +144,15 @@ def cmd_hostname_list(args, app): print(f"Error: User '{args.user}' not found.") return 1 + query = query.order_by(User.username, Hostname.hostname, Hostname.zone) + hostnames = list(query) if not hostnames: print("No hostnames found.") return 0 print( - f"\n{'Hostname':<35} {'User':<15} {'Zone':<20} " + f"\n{'Hostname':<35} {'Zone':<20} {'User':<15} " f"{'DNS-TTL':<8} {'Exp-TTL':<8} {'Last-Update IPv4':<25} {'Last-Update IPv6'}" ) print("-" * 140) @@ -158,7 +160,7 @@ def cmd_hostname_list(args, app): last_ipv4_update = datetime_str(h.last_ipv4_update) last_ipv6_update = datetime_str(h.last_ipv6_update) print( - f"{h.hostname:<35} {h.user.username:<15} {h.zone:<20} " + f"{h.hostname:<35} {h.zone:<20} {h.user.username:<15} " f"{h.dns_ttl:<8} {h.expiry_ttl:<8} {last_ipv4_update:<25} {last_ipv6_update}" ) return 0