33from argparse import ArgumentParser
44
55from .config import get_target_config , to_omada_connection
6- from .util import assert_target_argument
6+ from .util import dump_raw_data , get_mac , get_target_argument
77
88async def command_switch (args ) -> int :
99 """Executes 'switch' command"""
10- controller = assert_target_argument (args )
10+ controller = get_target_argument (args )
1111 config = get_target_config (controller )
1212
1313 async with to_omada_connection (config ) as client :
1414 site_client = await client .get_site_client (config .site )
15- switch = await site_client .get_switch (args ['mac' ])
15+ mac = await get_mac (site_client , args ['mac' ])
16+ switch = await site_client .get_switch (mac )
1617 print (f"Name: { switch .name } " )
1718 print (f"Address: { switch .mac } ({ switch .ip_address } )" )
1819 print (f"Ports: { switch .number_of_ports } " )
@@ -29,6 +30,8 @@ async def command_switch(args) -> int:
2930 for downlink in switch .downlink :
3031 print (f"- { downlink .mac } { downlink .name } " )
3132
33+ dump_raw_data (args , switch )
34+
3235 return 0
3336
3437def arg_parser (subparsers ) -> None :
@@ -41,5 +44,7 @@ def arg_parser(subparsers) -> None:
4144
4245 switch_parser .add_argument (
4346 "mac" ,
44- help = "The MAC address of the switch" ,
47+ help = "The MAC address or name of the switch" ,
4548 )
49+ switch_parser .add_argument ('-d' , '--dump' , help = "Output raw device information" , action = 'store_true' )
50+
0 commit comments