Skip to content

Commit

Permalink
refactor: move config messages to other dict
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalinDe committed Mar 19, 2024
1 parent 637a90b commit 14042f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
12 changes: 8 additions & 4 deletions pusteblume/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def generate_default_config():
with CONFIG_FILE.open("w") as fp:
default_config.write(fp)
print(
pusteblume.output.MESSAGES["config"]["generate_default_config"].format(
pusteblume.output.OUTPUT["config"]["messages"][
"generate_default_config"
].format(
config_file=CONFIG_FILE,
)
)
Expand All @@ -74,15 +76,17 @@ def validate_config(config):
for section in CONFIG_SECTIONS:
if section not in config.sections():
errors.append(
pusteblume.output.ERRORS["config"]["missing_section"].format(
pusteblume.output.OUTPUT["config"]["errors"]["missing_section"].format(
section=section,
)
)
else:
for key in CONFIG_SECTIONS[section]:
if key not in config[section]:
errors.append(
pusteblume.output.ERRORS["config"]["missing_key"].format(
pusteblume.output.OUTPUT["config"]["errors"][
"missing_key"
].format(
key=key,
section=section,
),
Expand All @@ -91,7 +95,7 @@ def validate_config(config):
raise InvalidConfig(
os.linesep.join(
(
pusteblume.output.ERRORS["config"]["errors"].format(
pusteblume.output.OUTPUT["config"]["errors"]["errors"].format(
config_file=CONFIG_FILE,
),
*errors,
Expand Down
22 changes: 10 additions & 12 deletions pusteblume/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
"invalid_tag": "'{string}' is not a valid tag",
},
},
"config": {
"messages": {
"generate_default_config": "generated default configuration file {config_file}",
},
"errors": {
"missing_section": "required section '{section}' missing",
"missing_key": "required key '{key}' in section '{section}' missing",
"errors": "configuration file {config_file} contains errors",
},
},
"main": {
"messages": {},
"errors": {
Expand All @@ -70,18 +80,6 @@
"errors": {},
},
}
MESSAGES = {
"config": {
"generate_default_config": "generated default configuration file {config_file}",
},
}
ERRORS = {
"config": {
"missing_section": "required section '{section}' missing",
"missing_key": "required key '{key}' in section '{section}' missing",
"errors": "configuration file {config_file} contains errors",
},
}
COLOURS = {
"fg": {
"black": 30,
Expand Down

0 comments on commit 14042f9

Please sign in to comment.