Skip to content

Commit 0e7aef5

Browse files
committed
[cli] Make config parser return Enums for overrides
1 parent bf55e71 commit 0e7aef5

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

scenedetect/_cli/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
CONFIG_MAP,
3636
DEFAULT_JPG_QUALITY,
3737
DEFAULT_WEBP_QUALITY,
38-
XmlFormat,
3938
)
4039
from scenedetect._cli.context import USER_CONFIG, CliContext, check_split_video_requirements
4140
from scenedetect.backends import AVAILABLE_BACKENDS
@@ -1668,11 +1667,9 @@ def save_xml_command(
16681667
ctx = ctx.obj
16691668
assert isinstance(ctx, CliContext)
16701669

1671-
# TODO: Change config parser so get_value returns enums directly.
1672-
format = XmlFormat[ctx.config.get_value("save-xml", "format", format).upper()]
16731670
save_xml_args = {
16741671
"filename": ctx.config.get_value("save-xml", "filename", filename),
1675-
"format": format,
1672+
"format": ctx.config.get_value("save-xml", "format", format),
16761673
"output": ctx.config.get_value("save-xml", "output", output),
16771674
}
16781675
ctx.add_command(cli_commands.save_xml, save_xml_args)

scenedetect/_cli/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,6 @@ class XmlFormat(Enum):
450450
The types of these values are used when decoding the configuration file. Valid choices for
451451
certain string options are stored in `CHOICE_MAP`."""
452452

453-
# TODO: Use the fact that all enums derive from the Enum class to avoid duplicating their values
454-
# here in the choice map.
455453
CHOICE_MAP: ty.Dict[str, ty.Dict[str, ty.List[str]]] = {
456454
"backend-pyav": {
457455
"threading_mode": [mode.lower() for mode in PYAV_THREADING_MODES],
@@ -765,8 +763,10 @@ def get_value(
765763
value = self._config[command][option]
766764
else:
767765
value = CONFIG_MAP[command][option]
768-
if issubclass(type(value), ValidatedValue):
766+
if isinstance(value, ValidatedValue):
769767
return value.value
768+
if isinstance(CONFIG_MAP[command][option], Enum) and isinstance(override, str):
769+
return CONFIG_MAP[command][option].__class__[value.upper().strip()]
770770
return value
771771

772772
def get_help_string(

0 commit comments

Comments
 (0)