Skip to content

Commit

Permalink
[cli] Move output command state out of CliContext (#426)
Browse files Browse the repository at this point in the history
* [cli] Move output command state out of CliContext

To simplify things, all output commands can be treated similarily
as they all act on the result of the processing pipeline. This
allows new commands to be added without needing to explicitly define
their values in CliContext, and makes the values that do remain there
much more meaningful.

It also allows commands to be specified multiple times gracefully
and with different options, so for example `save-images` can now be
run twice with different encoding parameters.

* [cli] Centralize preconditions in CliContext

* [cli] Simplify parsing of default values
  • Loading branch information
Breakthrough authored Oct 6, 2024
1 parent e58f0e3 commit 81e6a56
Show file tree
Hide file tree
Showing 8 changed files with 618 additions and 790 deletions.
10 changes: 5 additions & 5 deletions scenedetect/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

def main():
"""PySceneDetect command-line interface (CLI) entry point."""
cli_ctx = CliContext()
context = CliContext()
try:
# Process command line arguments and subcommands to initialize the context.
scenedetect.main(obj=cli_ctx) # Parse CLI arguments with registered callbacks.
scenedetect.main(obj=context) # Parse CLI arguments with registered callbacks.
except SystemExit as exit:
help_command = any(arg in sys.argv for arg in ["-h", "--help"])
if help_command or exit.code != 0:
Expand All @@ -38,12 +38,12 @@ def main():
# no progress bars get created, we instead create a fake context manager. This is done here
# to avoid needing a separate context manager at each point a progress bar is created.
log_redirect = (
FakeTqdmLoggingRedirect() if cli_ctx.quiet_mode else logging_redirect_tqdm(loggers=[logger])
FakeTqdmLoggingRedirect() if context.quiet_mode else logging_redirect_tqdm(loggers=[logger])
)

with log_redirect:
try:
run_scenedetect(cli_ctx)
run_scenedetect(context)
except KeyboardInterrupt:
logger.info("Stopped.")
if __debug__:
Expand All @@ -52,7 +52,7 @@ def main():
if __debug__:
raise
else:
logger.critical("Unhandled exception:", exc_info=ex)
logger.critical("ERROR: Unhandled exception:", exc_info=ex)
raise SystemExit(1) from None


Expand Down
Loading

0 comments on commit 81e6a56

Please sign in to comment.