Skip to content

Commit 11b6249

Browse files
committed
cli/__init__.py: dynamically adjust default response option in --stay-connected menu and fix firmware version info
1 parent d07b2f0 commit 11b6249

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

pybricksdev/cli/__init__.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,15 @@ async def reconnect_hub():
277277
"Change Target File",
278278
"Exit",
279279
]
280+
# the entry that is selected by default when the menu opens
281+
# this is overridden after the user picks an option
282+
# so that the default option is always the one that was last chosen
283+
default_response_option = (
284+
ResponseOptions.RECOMPILE_RUN
285+
if args.start
286+
else ResponseOptions.RECOMPILE_DOWNLOAD
287+
)
288+
280289
while True:
281290
try:
282291
if args.file is sys.stdin:
@@ -293,13 +302,7 @@ async def reconnect_hub():
293302
questionary.select(
294303
f"Would you like to re-compile {os.path.basename(args.file.name)}?",
295304
response_options,
296-
default=(
297-
response_options[ResponseOptions.RECOMPILE_RUN]
298-
if args.start
299-
else response_options[
300-
ResponseOptions.RECOMPILE_DOWNLOAD
301-
]
302-
),
305+
default=(response_options[default_response_option]),
303306
).ask_async()
304307
)
305308
)
@@ -308,18 +311,23 @@ async def reconnect_hub():
308311

309312
case ResponseOptions.RECOMPILE_RUN:
310313
with _get_script_path(args.file) as script_path:
314+
default_response_option = ResponseOptions.RECOMPILE_RUN
311315
await hub.run(script_path, wait=True)
312316

313317
case ResponseOptions.RECOMPILE_DOWNLOAD:
314318
with _get_script_path(args.file) as script_path:
319+
default_response_option = (
320+
ResponseOptions.RECOMPILE_DOWNLOAD
321+
)
315322
await hub.download(script_path)
316323

317324
case ResponseOptions.RUN_STORED:
318-
if hub.fw_version < Version("v1.2.0"):
325+
if hub.fw_version < Version("v3.3.0"):
319326
print(
320-
"Running a stored program remotely is only supported in firmware version >= v1.2.0."
327+
"Running a stored program remotely is only supported in the hub firmware version >= v3.3.0."
321328
)
322329
else:
330+
default_response_option = ResponseOptions.RUN_STORED
323331
await hub.start_user_program()
324332
await hub._wait_for_user_program_stop()
325333

0 commit comments

Comments
 (0)