@@ -95,18 +95,19 @@ def add_parser(self, subparsers: argparse._SubParsersAction):
9595 help = "connection type: %(choices)s" ,
9696 choices = ["ble" , "usb" , "ssh" ],
9797 )
98- parser .add_argument (
99- "device" ,
100- metavar = "<device>" ,
101- help = "hostname or IP address for SSH connection; "
102- "Bluetooth device name or Bluetooth address for BLE connection; "
103- "serial port name for USB connection" ,
104- )
10598 parser .add_argument (
10699 "script" ,
107100 metavar = "<script>" ,
108101 help = "path to a MicroPython script or inline script" ,
109102 )
103+ parser .add_argument (
104+ "--name" ,
105+ metavar = "<name>" ,
106+ required = False ,
107+ help = "hostname or IP address for SSH connection; "
108+ "Bluetooth device name or Bluetooth address for BLE connection; "
109+ "serial port name for USB connection" ,
110+ )
110111 parser .add_argument (
111112 "--wait" ,
112113 help = "Await program completion (True) or disconnect immediately (False)" ,
@@ -130,22 +131,31 @@ async def run(self, args: argparse.Namespace):
130131 # Pick the right connection
131132 if args .conntype == "ssh" :
132133 # So it's an ev3dev
133- if not validators .ip_address .ipv4 (args .device ):
134+ if args .name is None :
135+ print ("--name is required for SSH connections" , file = sys .stderr )
136+ exit (1 )
137+
138+ if not validators .ip_address .ipv4 (args .name ):
134139 raise ValueError ("Device must be IP address." )
140+
135141 hub = EV3Connection ()
136- device_or_address = args .device
142+ device_or_address = args .name
137143 elif args .conntype == "ble" :
138144 # It is a Pybricks Hub with BLE. Device name or address is given.
139145 hub = PybricksHub ()
140- device_or_address = await find_device (args .device )
141- elif args .conntype == "usb" and args .device == "lego" :
146+ device_or_address = await find_device (args .name )
147+ elif args .conntype == "usb" and args .name == "lego" :
142148 # It's LEGO stock firmware Hub with USB.
143149 hub = USBRPCConnection ()
144150 device_or_address = "LEGO Technic Large Hub in FS Mode"
145151 elif args .conntype == "usb" :
152+ if args .name is None :
153+ print ("--name is required for USB connections" , file = sys .stderr )
154+ exit (1 )
155+
146156 # It's a Pybricks Hub with USB. Port name is given.
147157 hub = USBPUPConnection ()
148- device_or_address = args .device
158+ device_or_address = args .name
149159 else :
150160 raise ValueError (f"Unknown connection type: { args .conntype } " )
151161
0 commit comments