feat(cli): add --silent option

This commit is contained in:
tretrauit 2023-06-30 20:55:53 +07:00
parent 69a53da8ae
commit 5b916025f3
3 changed files with 30 additions and 10 deletions

View File

@ -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)

View File

@ -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())

View File

@ -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)