Skip to content
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Added the `Change Target File` option to the `--stay-connected` menu.
([pybricksdev#123])

[pybricksdev#123]: https://github.com/pybricks/pybricksdev/pull/123

## [2.1.1] - 2025-09-13

### Fixed
Expand Down
33 changes: 27 additions & 6 deletions pybricksdev/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ async def reconnect_hub():
return hub

response_options = [
"Change Target File",
"Recompile and Run",
"Recompile and Download",
"Exit",
Expand All @@ -280,21 +281,38 @@ async def reconnect_hub():
response = await hub.race_disconnect(
hub.race_power_button_press(
questionary.select(
"Would you like to re-compile your code?",
f"Would you like to re-compile {os.path.basename(args.file.name)}?",
response_options,
default=(
response_options[0]
response_options[1]
if args.start
else response_options[1]
else response_options[2]
),
).ask_async()
)
)

if response == response_options[0]:
args.file.close()
args.file = open(
await hub.race_disconnect(
hub.race_power_button_press(
questionary.path(
"What file would you like to use?"
).ask_async()
)
)
)

with _get_script_path(args.file) as script_path:
if response == response_options[0]:
await hub.run(script_path, wait=True)
elif response == response_options[1]:
# send the new target file to the hub
if (
response == response_options[0]
or response == response_options[2]
):
await hub.download(script_path)
elif response == response_options[1]:
await hub.run(script_path, wait=True)
else:
return

Expand All @@ -314,6 +332,9 @@ async def reconnect_hub():
await asyncio.sleep(0.3)
hub = await reconnect_hub()

except FileNotFoundError:
print("Your file is invalid.")

finally:
await hub.disconnect()

Expand Down