Skip to content

Commit 4abd21d

Browse files
committed
cli: Enable starting REPL.
1 parent 15c9d64 commit 4abd21d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

pybricksdev/cli/__init__.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def add_parser(self, subparsers: argparse._SubParsersAction):
101101
parser.add_argument(
102102
"file",
103103
metavar="<file>",
104-
help="path to a MicroPython script or `-` for stdin",
104+
help="path to a MicroPython script, `-` for stdin, or `repl` for interactive prompt",
105105
type=str,
106106
)
107107
parser.add_argument(
@@ -180,15 +180,21 @@ def is_pybricks_usb(dev):
180180
# Connect to the address and run the script
181181
await hub.connect()
182182
try:
183-
if args.file == "-":
184-
with NamedTemporaryFile(suffix=".py", delete=False) as temp:
185-
temp.write(sys.stdin.buffer.read())
186-
args.file = temp.name
187-
188-
if args.start:
189-
await hub.run(args.file, args.wait)
183+
# Handle builtin programs.
184+
if args.file == "repl":
185+
await hub.run(128)
190186
else:
191-
await hub.download(args.file)
187+
# If using stdin, save to temporary file first.
188+
if args.file == "-":
189+
with NamedTemporaryFile(suffix=".py", delete=False) as temp:
190+
temp.write(sys.stdin.buffer.read())
191+
args.file = temp.name
192+
193+
# Download program and optionally start it.
194+
if args.start:
195+
await hub.run(args.file, args.wait)
196+
else:
197+
await hub.download(args.file)
192198
finally:
193199
await hub.disconnect()
194200

0 commit comments

Comments
 (0)