@@ -109,13 +109,28 @@ def add_parser(self, subparsers: argparse._SubParsersAction):
109109 "Bluetooth device name or Bluetooth address for BLE connection; "
110110 "serial port name for USB connection" ,
111111 )
112- parser .add_argument (
113- "--wait" ,
114- help = "Await program completion (True) or disconnect immediately (False)" ,
115- required = False ,
116- default = "True" ,
117- choices = ["True" , "False" ],
118- )
112+
113+ if hasattr (argparse , "BooleanOptionalAction" ):
114+ # BooleanOptionalAction requires Python 3.9
115+ parser .add_argument (
116+ "--wait" ,
117+ help = "wait for the program to complete before disconnecting" ,
118+ action = argparse .BooleanOptionalAction ,
119+ default = True ,
120+ )
121+ else :
122+ parser .add_argument (
123+ "--wait" ,
124+ help = "wait for the program to complete before disconnecting (default)" ,
125+ action = "store_true" ,
126+ default = True ,
127+ )
128+ parser .add_argument (
129+ "--no-wait" ,
130+ help = "disconnect as soon as program is done downloading" ,
131+ action = "store_false" ,
132+ dest = "wait" ,
133+ )
119134
120135 async def run (self , args : argparse .Namespace ):
121136 from ..ble import find_device
@@ -165,7 +180,7 @@ async def run(self, args: argparse.Namespace):
165180 # Connect to the address and run the script
166181 await hub .connect (device_or_address )
167182 try :
168- await hub .run (script_path , args .wait == "True" )
183+ await hub .run (script_path , args .wait )
169184 finally :
170185 await hub .disconnect ()
171186
0 commit comments