Skip to content

Commit

Permalink
refactor(config): common methods for writing errors/warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Jan 14, 2025
1 parent 5ed3833 commit 6c03e43
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pikaur/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,21 @@ class ConfigValueType(TypedDict):


def _err_write(message: str) -> None:
sys.stderr.write(f"{message}\n")
sys.stderr.write(" ".join([
DECORATION,
translate("error:"),
message,
"\n",
]))


def _warn_write(message: str) -> None:
sys.stderr.write(" ".join([
DECORATION,
translate("warning:"),
message,
"\n",
]))


class IntOrBoolSingleton(int):
Expand Down Expand Up @@ -771,9 +785,7 @@ def _migrate_deprecated_config_key(
old_value_was_removed = True

if old_value_was_migrated or old_value_was_removed:
_err_write(" ".join([
DECORATION,
translate("warning:"),
_warn_write(" ".join([
translate(
'Migrating [{}]{}="{}" config option to [{}]{}="{}"...',
).format(
Expand Down Expand Up @@ -801,9 +813,7 @@ def _migrate_deprecated_config_value(
new_default_value = option_schema["default"]
cls._config[section_name][option_name] = new_default_value
ConfigSchema()[section_name][option_name]["migrated"] = True
_err_write(" ".join([
DECORATION,
translate("warning:"),
_warn_write(" ".join([
translate(
'Migrating [{}]{}="{}" config option to ="{}"...',
).format(
Expand Down Expand Up @@ -843,9 +853,7 @@ def _handle_warning(
except (KeyError, configparser.NoSectionError):
return
if current_value in option_schema["warning"]["when_value"]:
_err_write("\n".join([
"",
translate("warning:"),
_warn_write("\n".join([
f" [{section_name}]{option_name} = {current_value}",
option_schema["warning"]["message"],
"\n",
Expand Down

0 comments on commit 6c03e43

Please sign in to comment.