|
16 | 16 |
|
17 | 17 | from pybricksdev import __name__ as MODULE_NAME |
18 | 18 | from pybricksdev import __version__ as MODULE_VERSION |
| 19 | +from pybricksdev.ble.pybricks import UserProgramId |
19 | 20 |
|
20 | 21 | PROG_NAME = ( |
21 | 22 | f"{path.basename(sys.executable)} -m {MODULE_NAME}" |
@@ -97,7 +98,7 @@ def add_parser(self, subparsers: argparse._SubParsersAction): |
97 | 98 | parser.add_argument( |
98 | 99 | "file", |
99 | 100 | metavar="<file>", |
100 | | - help="path to a MicroPython script or `-` for stdin", |
| 101 | + help="path to a MicroPython script, `-` for stdin, or `repl` for interactive prompt", |
101 | 102 | type=str, |
102 | 103 | ) |
103 | 104 | parser.add_argument( |
@@ -176,15 +177,21 @@ def is_pybricks_usb(dev): |
176 | 177 | # Connect to the address and run the script |
177 | 178 | await hub.connect() |
178 | 179 | 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) |
| 180 | + # Handle builtin programs. |
| 181 | + if args.file == "repl": |
| 182 | + await hub.run(UserProgramId.REPL) |
186 | 183 | else: |
187 | | - await hub.download(args.file) |
| 184 | + # If using stdin, save to temporary file first. |
| 185 | + if args.file == "-": |
| 186 | + with NamedTemporaryFile(suffix=".py", delete=False) as temp: |
| 187 | + temp.write(sys.stdin.buffer.read()) |
| 188 | + args.file = temp.name |
| 189 | + |
| 190 | + # Download program and optionally start it. |
| 191 | + if args.start: |
| 192 | + await hub.run(args.file, args.wait) |
| 193 | + else: |
| 194 | + await hub.download(args.file) |
188 | 195 | finally: |
189 | 196 | await hub.disconnect() |
190 | 197 |
|
|
0 commit comments