Skip to content

Commit

Permalink
cli: always sort lo first in 'show interfaces'
Browse files Browse the repository at this point in the history
This fixes #545

Signed-off-by: Mattias Walström <[email protected]>
  • Loading branch information
mattiaswal committed Aug 14, 2024
1 parent 21c1b25 commit c00dfa6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/statd/python/cli_pretty/cli_pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,15 @@ def find_iface(_ifaces, name):

return False


def version_sort(iface):
return [int(x) if x.isdigit() else x for x in re.split(r'(\d+)', iface['name'])]

def print_interface(iface):
iface.pr_name()
iface.pr_proto_eth()
iface.pr_proto_ipv4()
iface.pr_proto_ipv6()

def pr_interface_list(json):
hdr = (f"{'INTERFACE':<{Pad.iface}}"
f"{'PROTOCOL':<{Pad.proto}}"
Expand All @@ -452,7 +457,14 @@ def pr_interface_list(json):

ifaces = sorted(json["ietf-interfaces:interfaces"]["interface"], key=version_sort)

iface = find_iface(ifaces, "lo")
if iface:
print_interface(iface)

for iface in [Iface(data) for data in ifaces]:
if iface.name == "lo":
continue

if iface.is_bridge():
iface.pr_bridge(ifaces)
continue
Expand All @@ -470,11 +482,7 @@ def pr_interface_list(json):
continue
if iface.bridge:
continue

iface.pr_name()
iface.pr_proto_eth()
iface.pr_proto_ipv4()
iface.pr_proto_ipv6()
print_interface(iface)

def show_interfaces(json, name):
if name:
Expand Down

0 comments on commit c00dfa6

Please sign in to comment.