Skip to content

Commit 8b6bfa1

Browse files
CopilotJosverl
andauthored
Add --reset/--no-reset option to the list command
Agent-Logs-Url: https://github.com/Josverl/mpflash/sessions/aa67b28c-fcbb-42ff-96d6-db87d158f265 Co-authored-by: Josverl <981654+Josverl@users.noreply.github.com>
1 parent 92cf9db commit 8b6bfa1

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

mpflash/cli_list.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,15 @@
6262
show_default=True,
6363
help="""Show progress""",
6464
)
65-
def cli_list_mcus(serial: List[str], ignore: List[str], bluetooth: bool, as_json: bool, progress: bool = True) -> int:
65+
@click.option(
66+
"--reset/--no-reset",
67+
"reset",
68+
is_flag=True,
69+
default=True,
70+
show_default=True,
71+
help="""Reset the board after listing.""",
72+
)
73+
def cli_list_mcus(serial: List[str], ignore: List[str], bluetooth: bool, as_json: bool, progress: bool = True, reset: bool = True) -> int:
6674
"""List the connected MCU boards, and output in a nice table or json."""
6775
from .connected import list_mcus
6876
from .list import show_mcus
@@ -82,13 +90,14 @@ def cli_list_mcus(serial: List[str], ignore: List[str], bluetooth: bool, as_json
8290

8391
if progress:
8492
show_mcus(conn_mcus, refresh=False)
85-
for mcu in conn_mcus:
86-
# reset the board so it can continue to whatever it was running before
87-
if mcu.family == "circuitpython":
88-
# CircuitPython boards need a special reset command
89-
mcu.run_command(["exec", "--no-follow", "import microcontroller,time;time.sleep(0.01);microcontroller.reset()"], resume=False)
90-
elif mcu.family == "unknown":
91-
continue
92-
else:
93-
mcu.run_command("reset")
93+
if reset:
94+
for mcu in conn_mcus:
95+
# reset the board so it can continue to whatever it was running before
96+
if mcu.family == "circuitpython":
97+
# CircuitPython boards need a special reset command
98+
mcu.run_command(["exec", "--no-follow", "import microcontroller,time;time.sleep(0.01);microcontroller.reset()"], resume=False)
99+
elif mcu.family == "unknown":
100+
continue
101+
else:
102+
mcu.run_command("reset")
94103
return 0 if conn_mcus else 1

tests/cli/test_cli_list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
("2", 0, ["list", "--json"]),
2323
("3", 0, ["list", "--no-progress"]),
2424
("4", 0, ["list", "--json", "--no-progress"]),
25+
("5", 0, ["list", "--no-reset"]),
26+
("6", 0, ["list", "--reset"]),
2527
],
2628
)
2729
def test_mpflash_list(id, ex_code, args: List[str], mocker: MockerFixture):

0 commit comments

Comments
 (0)