Skip to content

Commit ee875a5

Browse files
committed
Introduction of a friendly user setup checker.
This patch fixes #274. Indeed, before this patch, there was no was to send some message to the user when some common setup mistakes were found. This patch fixes it by adding a "message collector" that is later printed the end user. For now on, the configuration checker only checks against #274, but this patch opens the door for other improvement in the future. Contributors: * @ZeroDot1 * @spirillen
1 parent c019494 commit ee875a5

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

PyFunceble/cli/storage.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
import os
5454
import sys
55-
from typing import Optional
55+
from typing import List, Optional
5656

5757
import colorama
5858
from box import Box
@@ -213,3 +213,6 @@
213213
PyFunceble.cli.storage_facility.get_output_directory(),
214214
OUTPUTS.parent_directory,
215215
)
216+
217+
# This one will store some extra messages to print to the user.
218+
EXTRA_MESSAGES: Optional[List[str]] = []

PyFunceble/cli/system/integrator.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353

5454
import os
5555

56+
import colorama
57+
5658
import PyFunceble.cli.facility
5759
import PyFunceble.cli.factory
5860
import PyFunceble.cli.storage
@@ -151,6 +153,30 @@ def inject_into_config(self) -> "SystemIntegrator":
151153

152154
return self
153155

156+
@SystemBase.ensure_args_is_given
157+
def check_config(self) -> "SystemIntegrator":
158+
"""
159+
Checks or do some sanity check of the configuration.
160+
161+
This method will basically check that the common mistakes while mixing
162+
configuration and CLI arguments are not found.
163+
164+
.. warning::
165+
The messages are not directly printed, but rather stored in the
166+
PyFunceble.cli.storage.EXTRA_MESSAGES list.
167+
"""
168+
169+
if (
170+
not PyFunceble.storage.CONFIGURATION.cli_testing.file_generation.hosts
171+
and not PyFunceble.storage.CONFIGURATION.cli_testing.file_generation.plain
172+
):
173+
PyFunceble.cli.storage.EXTRA_MESSAGES.append(
174+
f"{colorama.Style.BRIGHT}{colorama.Fore.MAGENTA}Your setup won't "
175+
"generate any output! "
176+
"Reason: file_generation.hosts and file_generation.plain are "
177+
"both disabled."
178+
)
179+
154180
@SystemBase.ensure_args_is_given
155181
def start(self) -> "SystemIntegrator":
156182
"""
@@ -170,6 +196,7 @@ def start(self) -> "SystemIntegrator":
170196
PyFunceble.facility.Logger.debug("Given arguments:\n%r", self.args)
171197

172198
self.inject_into_config()
199+
self.check_config()
173200

174201
PyFunceble.cli.facility.CredentialLoader.start()
175202
PyFunceble.cli.factory.DBSession.init_db_sessions()

PyFunceble/cli/utils/version.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import PyFunceble.cli.storage
6161
import PyFunceble.facility
6262
import PyFunceble.storage
63+
from PyFunceble.cli.utils.stdout import print_single_line
6364
from PyFunceble.converter.internal_url import InternalUrlConverter
6465
from PyFunceble.helpers.dict import DictHelper
6566
from PyFunceble.helpers.download import DownloadHelper
@@ -340,7 +341,7 @@ def handle_messages(upstream_version: Box) -> None:
340341

341342
def print_central_messages(check_force_update: bool = False) -> None:
342343
"""
343-
Compares the version with the upstream one and handle the messages.
344+
Collect all possible messages from upstream and downstream and print them.
344345
"""
345346

346347
upstream_version = get_upstream_version()
@@ -355,3 +356,6 @@ def print_central_messages(check_force_update: bool = False) -> None:
355356
)
356357

357358
handle_messages(upstream_version)
359+
360+
for extra_message in PyFunceble.cli.storage.EXTRA_MESSAGES:
361+
print_single_line(extra_message, force=True)

0 commit comments

Comments
 (0)