From 5b916025f37f8351ea5f3956b64fc1b48bfabcc7 Mon Sep 17 00:00:00 2001 From: tretrauit Date: Fri, 30 Jun 2023 20:55:53 +0700 Subject: [PATCH] feat(cli): add --silent option --- vollerei/cli/__init__.py | 21 ++++++++++++++------- vollerei/cli/hsr.py | 9 ++++++--- vollerei/cli/utils.py | 10 ++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/vollerei/cli/__init__.py b/vollerei/cli/__init__.py index 0ea5d18..059c0c0 100644 --- a/vollerei/cli/__init__.py +++ b/vollerei/cli/__init__.py @@ -3,26 +3,33 @@ from vollerei import __version__ from vollerei.cli.hsr import HSR from vollerei.hsr import PatchType from vollerei.cli import utils +from vollerei.cli.utils import msg class CLI: def __init__( - self, game_path: str = None, patch_type=None, noconfirm: bool = False + self, + game_path: str = None, + patch_type=None, + noconfirm: bool = False, + silent: bool = False, ) -> None: """ Vollerei CLI """ - print(f"Vollerei v{__version__}") + utils.silent_message = silent + msg(f"Vollerei v{__version__}") if noconfirm: - print("User requested to automatically answer yes to all questions.") + msg("User requested to automatically answer yes to all questions.") utils.no_confirm = noconfirm if not game_path: game_path = Path.cwd() game_path = Path(game_path) + hsr_patch_type = patch_type if patch_type is None: - patch_type = PatchType.Jadeite + hsr_patch_type = PatchType.Jadeite elif isinstance(patch_type, str): - patch_type = PatchType[patch_type] + hsr_patch_type = PatchType[patch_type] elif isinstance(patch_type, int): - patch_type = PatchType(patch_type) - self.hsr = HSR(game_path=game_path, patch_type=patch_type) + hsr_patch_type = PatchType(patch_type) + self.hsr = HSR(game_path=game_path, patch_type=hsr_patch_type) diff --git a/vollerei/cli/hsr.py b/vollerei/cli/hsr.py index ab49326..dd5e611 100644 --- a/vollerei/cli/hsr.py +++ b/vollerei/cli/hsr.py @@ -1,6 +1,6 @@ from traceback import print_exc from platform import system -from vollerei.cli.utils import ask +from vollerei.cli.utils import ask, msg from vollerei.hsr import Game, Patcher from vollerei.exceptions.patcher import PatcherError, PatchUpdateError from vollerei.hsr.patcher import PatchType @@ -11,8 +11,8 @@ class HSR: self, game_path=None, patch_type: PatchType = PatchType.Jadeite ) -> None: self._game = Game(game_path) - print("Game directory:", self._game.path) - print("Game version:", self._game.get_version_str()) + msg("Game directory:", self._game.path) + msg("Game version:", self._game.get_version_str()) self._patcher = Patcher() self._patcher.patch_type = patch_type @@ -115,3 +115,6 @@ class HSR: self.__patch_jadeite() case PatchType.Astra: self.__patch_astra() + + def get_version(self): + print(self._game.get_version_str()) diff --git a/vollerei/cli/utils.py b/vollerei/cli/utils.py index 325d55b..d9acc43 100644 --- a/vollerei/cli/utils.py +++ b/vollerei/cli/utils.py @@ -1,4 +1,5 @@ no_confirm = False +silent_message = False def ask(question: str): @@ -12,3 +13,12 @@ def ask(question: str): # Pacman way, treat all other answers as no else: return False + + +def msg(*args, **kwargs): + """ + Print but silentable + """ + if silent_message: + return + print(*args, **kwargs)