summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2022-10-05 22:30:29 +1100
committerDamien George <damien@micropython.org>2022-10-06 00:58:31 +1100
commitf13134e40308c24bcb2c09084f17fc9d54efe5db (patch)
treee10cdd79be6d5a8335944df4c3fcb278673a3ec4
parent95c614e2b60b5c1c83c85aefe88a2aadbf43b9ed (diff)
tools/mpremote: Fix argument handling for follow and add help strings.
Fixes in this commit are: - Make --follow the default for "run" (accidentally changed in 68d094358). - Add help strings for "repl": --capture --inject-file --inject-code - Update help strings for "run". - Fix encoding for --inject-code (accidentally broken in 68d094358). - Remove ability to --no-follow for "eval". It was there previously because it shared the same code path with "exec" and "run", but makes no sense for "eval", so might as well remove. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
-rw-r--r--tools/mpremote/mpremote/commands.py2
-rw-r--r--tools/mpremote/mpremote/main.py29
-rw-r--r--tools/mpremote/mpremote/repl.py1
3 files changed, 24 insertions, 8 deletions
diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py
index bf56df699..558cd82f1 100644
--- a/tools/mpremote/mpremote/commands.py
+++ b/tools/mpremote/mpremote/commands.py
@@ -204,7 +204,7 @@ def do_exec(state, args):
def do_eval(state, args):
buf = "print(" + args.expr[0] + ")"
- _do_execbuffer(state, buf, args.follow)
+ _do_execbuffer(state, buf, True)
def do_run(state, args):
diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py
index 4f541685a..988ffe8f6 100644
--- a/tools/mpremote/mpremote/main.py
+++ b/tools/mpremote/mpremote/main.py
@@ -119,30 +119,45 @@ def argparse_mount():
def argparse_repl():
cmd_parser = argparse.ArgumentParser(description="connect to given device")
- cmd_parser.add_argument("--capture", type=str, required=False, help="TODO")
- cmd_parser.add_argument("--inject-code", type=str, required=False, help="TODO")
- cmd_parser.add_argument("--inject-file", type=str, required=False, help="TODO")
+ cmd_parser.add_argument(
+ "--capture",
+ type=str,
+ required=False,
+ help="saves a copy of the REPL session to the specified path",
+ )
+ cmd_parser.add_argument(
+ "--inject-code", type=str, required=False, help="code to be run when Ctrl-J is pressed"
+ )
+ cmd_parser.add_argument(
+ "--inject-file",
+ type=str,
+ required=False,
+ help="path to file to be run when Ctrl-K is pressed",
+ )
return cmd_parser
def argparse_eval():
cmd_parser = argparse.ArgumentParser(description="evaluate and print the string")
- _bool_flag(cmd_parser, "follow", "f", True, "TODO")
cmd_parser.add_argument("expr", nargs=1, help="expression to execute")
return cmd_parser
def argparse_exec():
cmd_parser = argparse.ArgumentParser(description="execute the string")
- _bool_flag(cmd_parser, "follow", "f", True, "TODO")
+ _bool_flag(
+ cmd_parser, "follow", "f", True, "follow output until the expression completes (default)"
+ )
cmd_parser.add_argument("expr", nargs=1, help="expression to execute")
return cmd_parser
def argparse_run():
cmd_parser = argparse.ArgumentParser(description="run the given local script")
- _bool_flag(cmd_parser, "follow", "f", False, "TODO")
- cmd_parser.add_argument("path", nargs=1, help="expression to execute")
+ _bool_flag(
+ cmd_parser, "follow", "f", True, "follow output until the script completes (default)"
+ )
+ cmd_parser.add_argument("path", nargs=1, help="path to script to execute")
return cmd_parser
diff --git a/tools/mpremote/mpremote/repl.py b/tools/mpremote/mpremote/repl.py
index 7da00c0fd..3d6ca1881 100644
--- a/tools/mpremote/mpremote/repl.py
+++ b/tools/mpremote/mpremote/repl.py
@@ -61,6 +61,7 @@ def do_repl(state, args):
print('Capturing session to file "%s"' % capture_file)
capture_file = open(capture_file, "wb")
if code_to_inject is not None:
+ code_to_inject = bytes(code_to_inject.replace("\\n", "\r\n"), "utf8")
print("Use Ctrl-J to inject", code_to_inject)
if file_to_inject is not None:
print('Use Ctrl-K to inject file "%s"' % file_to_inject)