Invoke the scenedetect CLI in-process using Click's CliRunner. Replicates the two-step execution of ``__main__.py``: 1. ``scenedetect.main(obj=context)`` - parse args and register callbacks on ``CliContext`` 2. ``run_scenedetect(context)`` - execute detection and output commands R
(args: list[str], catch_exceptions: bool = False)
| 19 | |
| 20 | |
| 21 | def invoke_cli(args: list[str], catch_exceptions: bool = False) -> tuple[int, str]: |
| 22 | """Invoke the scenedetect CLI in-process using Click's CliRunner. |
| 23 | |
| 24 | Replicates the two-step execution of ``__main__.py``: |
| 25 | |
| 26 | 1. ``scenedetect.main(obj=context)`` - parse args and register callbacks on ``CliContext`` |
| 27 | 2. ``run_scenedetect(context)`` - execute detection and output commands |
| 28 | |
| 29 | Returns ``(exit_code, output_text)``. |
| 30 | """ |
| 31 | context = CliContext() |
| 32 | runner = CliRunner() |
| 33 | result = runner.invoke(_scenedetect_cli, args, obj=context, catch_exceptions=catch_exceptions) |
| 34 | if result.exit_code == 0: |
| 35 | run_scenedetect(context) |
| 36 | return result.exit_code, result.output |