Skip to content

Commit a311e9e

Browse files
jimmodpgeorge
authored andcommitted
tools/mpremote: Allow + terminator for fs commands.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent 8f4c108 commit a311e9e

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

docs/reference/mpremote.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ For REPL access, running ``mpremote`` without any arguments is usually all that
3030
is needed. ``mpremote`` also supports a set of commands given at the command
3131
line which will perform various actions on remote MicroPython devices.
3232

33+
For commands that support multiple arguments (e.g. a list of files), the
34+
argument list can be terminated with ``+``.
35+
3336
The full list of supported commands are:
3437

3538
- connect to a specified device via a device-name shortcut:
@@ -248,3 +251,5 @@ Examples
248251
mpremote cp main.py :
249252
250253
mpremote cp -r dir/ :
254+
255+
mpremote cp a.py b.py : + repl

tools/mpremote/mpremote/main.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,19 @@ def show_progress_bar(size, total_size):
300300
)
301301

302302

303+
# Get all args up to the terminator ("+").
304+
# The passed args will be updated with these ones removed.
305+
def get_fs_args(args):
306+
n = 0
307+
for src in args:
308+
if src == "+":
309+
break
310+
n += 1
311+
fs_args = args[:n]
312+
args[:] = args[n + 1 :]
313+
return fs_args
314+
315+
303316
def do_filesystem(pyb, args):
304317
def _list_recursive(files, path):
305318
if os.path.isdir(path):
@@ -308,16 +321,18 @@ def _list_recursive(files, path):
308321
else:
309322
files.append(os.path.split(path))
310323

324+
fs_args = get_fs_args(args)
325+
311326
# Don't be verbose when using cat, so output can be redirected to something.
312-
verbose = args[0] != "cat"
327+
verbose = fs_args[0] != "cat"
313328

314-
if args[0] == "cp" and args[1] == "-r":
315-
args.pop(0)
316-
args.pop(0)
317-
assert args[-1] == ":"
318-
args.pop()
329+
if fs_args[0] == "cp" and fs_args[1] == "-r":
330+
fs_args.pop(0)
331+
fs_args.pop(0)
332+
assert fs_args[-1] == ":"
333+
fs_args.pop()
319334
src_files = []
320-
for path in args:
335+
for path in fs_args:
321336
_list_recursive(src_files, path)
322337
known_dirs = {""}
323338
pyb.exec_("import uos")
@@ -335,8 +350,9 @@ def _list_recursive(files, path):
335350
verbose=verbose,
336351
)
337352
else:
338-
pyboard.filesystem_command(pyb, args, progress_callback=show_progress_bar, verbose=verbose)
339-
args.clear()
353+
pyboard.filesystem_command(
354+
pyb, fs_args, progress_callback=show_progress_bar, verbose=verbose
355+
)
340356

341357

342358
def do_repl_main_loop(pyb, console_in, console_out_write, *, code_to_inject, file_to_inject):

0 commit comments

Comments
 (0)