|
31 | 31 | # Order of commands in help and completion |
32 | 32 | _CMD_ORDER = [ |
33 | 33 | 'ls', 'tree', 'cat', 'cp', 'mv', 'mkdir', 'rm', 'pwd', 'cd', 'path', |
34 | | - 'stop', 'reset', 'monitor', 'repl', 'exec', 'run', 'edit', 'info', |
| 34 | + 'stop', 'reset', 'wipe', 'monitor', 'repl', 'exec', 'run', 'edit', 'info', |
35 | 35 | 'rtc', 'flash', 'mount', 'ln', 'speedtest', 'sleep', 'ports', |
36 | 36 | ] |
37 | 37 |
|
@@ -770,6 +770,21 @@ def cmd_reset(self, mode='soft', reconnect=True, timeout=None): |
770 | 770 | except (NotImplementedError, _mpytool.ConnError) as err: |
771 | 771 | raise _mpytool.MpyError(f"Bootloader reset failed: {err}") |
772 | 772 |
|
| 773 | + def cmd_wipe(self, reconnect=True, timeout=None): |
| 774 | + """Erase all files from root, then machine-reset the device""" |
| 775 | + self.verbose("WIPE", 1) |
| 776 | + try: |
| 777 | + self.mpy.wipe( |
| 778 | + reconnect=reconnect, timeout=timeout, |
| 779 | + on_delete=lambda path: self.verbose(f" rm {path}", 1)) |
| 780 | + except (_mpytool.ConnError, OSError) as err: |
| 781 | + self.verbose(f" reconnect failed: {err}", 1, color='red') |
| 782 | + raise _mpytool.ConnError(f"Reconnect failed: {err}") |
| 783 | + if reconnect: |
| 784 | + self.verbose(" reset, reconnected", 1, color='green') |
| 785 | + else: |
| 786 | + self.verbose(" reset", 1) |
| 787 | + |
773 | 788 | @command('ls', 'List files and directories on device.') |
774 | 789 | @argument('path', nargs='?', default=':', metavar='remote', |
775 | 790 | type=_normalize_path_arg, help='device path (default: CWD)') |
@@ -922,6 +937,18 @@ def _dispatch_reset(self, commands, is_last_group): |
922 | 937 | reconnect = has_more if mode in ('machine', 'rts') else True |
923 | 938 | self.cmd_reset(mode=mode, reconnect=reconnect, timeout=args.timeout) |
924 | 939 |
|
| 940 | + @command('wipe', 'Erase ALL files and machine-reset the device.') |
| 941 | + @option('-y', '--yes', action='store_true', |
| 942 | + help='no-op (wipe never prompts), accepted for convenience') |
| 943 | + @option('-t', '--timeout', type=int, |
| 944 | + help='reconnect timeout in seconds') |
| 945 | + def _dispatch_wipe(self, commands, is_last_group): |
| 946 | + args, commands[:] = _make_parser( |
| 947 | + self._dispatch_wipe).parse_known_args(commands) |
| 948 | + # Reconnect only if more work follows; pointless if wipe is last. |
| 949 | + has_more = bool(commands) or not is_last_group |
| 950 | + self.cmd_wipe(reconnect=has_more, timeout=args.timeout) |
| 951 | + |
925 | 952 | @command('monitor', 'Monitor device output until program ends.') |
926 | 953 | @option('-f', '--follow', action='store_true', |
927 | 954 | help='follow output continuously (Ctrl-C to stop)') |
@@ -1441,7 +1468,7 @@ def _dispatch_args(self, commands, is_last_group): |
1441 | 1468 |
|
1442 | 1469 | _COMMANDS = frozenset({ |
1443 | 1470 | 'ls', 'tree', 'cat', 'mkdir', 'rm', 'pwd', 'cd', 'path', |
1444 | | - 'reset', 'stop', 'monitor', 'repl', 'exec', 'run', 'edit', 'info', |
| 1471 | + 'reset', 'wipe', 'stop', 'monitor', 'repl', 'exec', 'run', 'edit', 'info', |
1445 | 1472 | 'rtc', 'flash', 'sleep', 'cp', 'mv', 'mount', 'ln', 'speedtest', |
1446 | 1473 | 'ports', '_paths', '_commands', '_options', '_args', |
1447 | 1474 | }) |
|
0 commit comments