Skip to content

Commit a59f63e

Browse files
committed
cli: Enable starting REPL.
1 parent 4404331 commit a59f63e

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
@@ -97,7 +97,7 @@ def add_parser(self, subparsers: argparse._SubParsersAction):
9797
parser.add_argument(
9898
"file",
9999
metavar="<file>",
100-
help="path to a MicroPython script or `-` for stdin",
100+
help="path to a MicroPython script, `-` for stdin, or `repl` for interactive prompt",
101101
type=str,
102102
)
103103
parser.add_argument(
@@ -176,15 +176,21 @@ def is_pybricks_usb(dev):
176176
# Connect to the address and run the script
177177
await hub.connect()
178178
try:
179-
if args.file == "-":
180-
with NamedTemporaryFile(suffix=".py", delete=False) as temp:
181-
temp.write(sys.stdin.buffer.read())
182-
args.file = temp.name
183-
184-
if args.start:
185-
await hub.run(args.file, args.wait)
179+
# Handle builtin programs.
180+
if args.file == "repl":
181+
await hub.run(128)
186182
else:
187-
await hub.download(args.file)
183+
# If using stdin, save to temporary file first.
184+
if args.file == "-":
185+
with NamedTemporaryFile(suffix=".py", delete=False) as temp:
186+
temp.write(sys.stdin.buffer.read())
187+
args.file = temp.name
188+
189+
# Download program and optionally start it.
190+
if args.start:
191+
await hub.run(args.file, args.wait)
192+
else:
193+
await hub.download(args.file)
188194
finally:
189195
await hub.disconnect()
190196

0 commit comments

Comments
 (0)