Skip to content

Commit

Permalink
Simplified Ifconfig and IpAddress objects
Browse files Browse the repository at this point in the history
  • Loading branch information
signal-09 committed Sep 10, 2024
1 parent 7354613 commit ef678e2
Show file tree
Hide file tree
Showing 7 changed files with 635 additions and 528 deletions.
59 changes: 59 additions & 0 deletions iproute4mac/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import json

import iproute4mac.ifconfig as ifconfig
import iproute4mac.libc as libc
import iproute4mac.utils as utils

from difflib import unified_diff

from iproute4mac import OPTION
from iproute4mac.utils import matches, strcmp, next_arg


def usage():
utils.stderr("""\
Usage: ip debug { address | neigh | route }""")
exit(libc.EXIT_ERROR)


def debug_address(argv=[]):
old_options = utils.options_override({"show_details": True, "json": True, "pretty": True})
interfaces = ifconfig.Ifconfig()
utils.options_restore(old_options)
ip_ifconfig = str(interfaces)
os_ifconfig = ifconfig.run()

diff = unified_diff(ip_ifconfig.splitlines(), os_ifconfig.splitlines(), n=1000)
print("\n".join(list(diff)))


def debug_neigh(argv=[]):
pass


def debug_route(argv=[]):
pass


def all():
debug_address()
debug_neigh()
debug_route()


def do_debug(argv):
if not argv:
return all()

cmd = argv.pop(0)
if matches(cmd, "address"):
return debug_address(argv)
elif matches(cmd, "neighbor", "neighbour"):
return debug_neigh(argv)
elif matches(cmd, "route"):
return debug_route(argv)
elif matches(cmd, "help"):
return usage()

utils.stderr(f'Command "{cmd}" is unknown, try "ip debug help".')
exit(libc.EXIT_ERROR)
Loading

0 comments on commit ef678e2

Please sign in to comment.