Add Log ConsoleFormatSettings.from_string static method to get settings by name with default option

To help set from config or command line with fallback
This commit is contained in:
Clemens Schwaighofer
2025-11-19 13:45:26 +09:00
parent 06a17d7c30
commit 5996bb1fc0
2 changed files with 17 additions and 0 deletions

View File

@@ -52,6 +52,22 @@ class ConsoleFormatSettings:
# only message
BARE = ConsoleFormat(0)
@staticmethod
def from_string(setting_str: str, default: ConsoleFormat | None = None) -> ConsoleFormat | None:
"""
Get a console format setting, if does not exist set to None
Arguments:
setting_str {str} -- what to search for
default {ConsoleFormat | None} -- if not found return this (default: {None})
Returns:
ConsoleFormat | None -- found ConsoleFormat or None
"""
if hasattr(ConsoleFormatSettings, setting_str):
return getattr(ConsoleFormatSettings, setting_str)
return default
# MARK: Log settings TypedDict
class LogSettings(TypedDict):