Main program entry point
()
| 324 | |
| 325 | |
| 326 | def main(): |
| 327 | """ |
| 328 | Main program entry point |
| 329 | """ |
| 330 | enterRepl = sys.stdin.isatty() |
| 331 | forceRepl = False |
| 332 | globalInitModule = initGlobalThis() |
| 333 | global requirePath |
| 334 | |
| 335 | try: |
| 336 | opts, args = getopt.getopt(sys.argv[1:], "hie:p:r:v", ["help", "eval=", "print=", |
| 337 | "require=", "version", "interactive", "use-strict", "inspect", "wtf"]) |
| 338 | except getopt.GetoptError as err: |
| 339 | # print help information and exit: |
| 340 | print(err) # will print something like "option -a not recognized" |
| 341 | usage() |
| 342 | sys.exit(2) |
| 343 | output = None |
| 344 | verbose = False |
| 345 | enableWTF = False |
| 346 | for o, a in opts: |
| 347 | if o in ("-v", "--version"): |
| 348 | print(pm.__version__) |
| 349 | sys.exit() |
| 350 | elif o in ("--use-strict"): |
| 351 | evalOpts['strict'] = True |
| 352 | elif o in ("-h", "--help"): |
| 353 | usage() |
| 354 | sys.exit() |
| 355 | elif o in ("-i", "--interactive"): |
| 356 | forceRepl = True |
| 357 | elif o in ("-e", "--eval"): |
| 358 | async def runEval(): |
| 359 | pm.eval(a, evalOpts) |
| 360 | await pm.wait() |
| 361 | asyncio.run(runEval()) |
| 362 | enterRepl = False |
| 363 | elif o in ("-p", "--print"): |
| 364 | async def runEvalPrint(): |
| 365 | ret = pm.eval(a, evalOpts) |
| 366 | pm.eval("ret => console.log(ret)", evalOpts)(ret) |
| 367 | await pm.wait() |
| 368 | asyncio.run(runEvalPrint()) |
| 369 | enterRepl = False |
| 370 | elif o in ("-r", "--require"): |
| 371 | globalThis.require(a) |
| 372 | elif o in ("--inspect"): |
| 373 | pmdb.enable() |
| 374 | elif o in ("--wtf"): |
| 375 | enableWTF = True |
| 376 | else: |
| 377 | assert False, "unhandled option" |
| 378 | |
| 379 | if (len(args) > 0): |
| 380 | async def runJS(): |
| 381 | hasUncaughtException = False |
| 382 | loop = asyncio.get_running_loop() |
| 383 |
no test coverage detected