diff --git a/src/ape/cli/options.py b/src/ape/cli/options.py index e100ab6396..4331b7d151 100644 --- a/src/ape/cli/options.py +++ b/src/ape/cli/options.py @@ -56,7 +56,7 @@ def abort(msg: str, base_error: Optional[Exception] = None) -> NoReturn: def verbosity_option( - cli_logger: Optional[ApeLogger] = None, default: str = DEFAULT_LOG_LEVEL + cli_logger: Optional[ApeLogger] = None, default: Union[str, LogLevel] = DEFAULT_LOG_LEVEL ) -> Callable: """A decorator that adds a `--verbosity, -v` option to the decorated command. @@ -67,12 +67,12 @@ def verbosity_option( def _create_verbosity_kwargs( - _logger: Optional[ApeLogger] = None, default: str = DEFAULT_LOG_LEVEL + _logger: Optional[ApeLogger] = None, default: Union[str, LogLevel] = DEFAULT_LOG_LEVEL ) -> dict: cli_logger = _logger or logger def set_level(ctx, param, value): - cli_logger._load_from_sys_argv(default=value.upper()) + cli_logger._load_from_sys_argv(default=value.upper() if isinstance(value, str) else value) level_names = [lvl.name for lvl in LogLevel] names_str = f"{', '.join(level_names[:-1])}, or {level_names[-1]}" @@ -87,7 +87,8 @@ def set_level(ctx, param, value): def ape_cli_context( - default_log_level: str = DEFAULT_LOG_LEVEL, obj_type: type = ApeCliContextObject + default_log_level: Union[str, LogLevel] = DEFAULT_LOG_LEVEL, + obj_type: type = ApeCliContextObject, ) -> Callable: """ A ``click`` context object with helpful utilities. @@ -95,8 +96,8 @@ def ape_cli_context( such as logging or accessing managers. Args: - default_log_level (str): The log-level value to pass to - :meth:`~ape.cli.options.verbosity_option`. + default_log_level (Union[str, :class:`~ape.logging.LogLevel`]): The log-level + value to pass to :meth:`~ape.cli.options.verbosity_option`. obj_type (Type): The context object type. Defaults to :class:`~ape.cli.options.ApeCliContextObject`. Sub-class the context to extend its functionality in your CLIs, diff --git a/src/ape/logging.py b/src/ape/logging.py index 4d9e943de5..76d223f3c0 100644 --- a/src/ape/logging.py +++ b/src/ape/logging.py @@ -141,7 +141,7 @@ def format(self, fmt: Optional[str] = None): fmt = fmt or DEFAULT_LOG_FORMAT _format_logger(self._logger, fmt) - def _load_from_sys_argv(self, default: Optional[Union[str, int]] = None): + def _load_from_sys_argv(self, default: Optional[Union[str, int, LogLevel]] = None): """ Load from sys.argv to beat race condition with `click`. """