feat(cli): add --silent option
This commit is contained in:
parent
69a53da8ae
commit
5b916025f3
@ -3,26 +3,33 @@ from vollerei import __version__
|
|||||||
from vollerei.cli.hsr import HSR
|
from vollerei.cli.hsr import HSR
|
||||||
from vollerei.hsr import PatchType
|
from vollerei.hsr import PatchType
|
||||||
from vollerei.cli import utils
|
from vollerei.cli import utils
|
||||||
|
from vollerei.cli.utils import msg
|
||||||
|
|
||||||
|
|
||||||
class CLI:
|
class CLI:
|
||||||
def __init__(
|
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:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Vollerei CLI
|
Vollerei CLI
|
||||||
"""
|
"""
|
||||||
print(f"Vollerei v{__version__}")
|
utils.silent_message = silent
|
||||||
|
msg(f"Vollerei v{__version__}")
|
||||||
if noconfirm:
|
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
|
utils.no_confirm = noconfirm
|
||||||
if not game_path:
|
if not game_path:
|
||||||
game_path = Path.cwd()
|
game_path = Path.cwd()
|
||||||
game_path = Path(game_path)
|
game_path = Path(game_path)
|
||||||
|
hsr_patch_type = patch_type
|
||||||
if patch_type is None:
|
if patch_type is None:
|
||||||
patch_type = PatchType.Jadeite
|
hsr_patch_type = PatchType.Jadeite
|
||||||
elif isinstance(patch_type, str):
|
elif isinstance(patch_type, str):
|
||||||
patch_type = PatchType[patch_type]
|
hsr_patch_type = PatchType[patch_type]
|
||||||
elif isinstance(patch_type, int):
|
elif isinstance(patch_type, int):
|
||||||
patch_type = PatchType(patch_type)
|
hsr_patch_type = PatchType(patch_type)
|
||||||
self.hsr = HSR(game_path=game_path, patch_type=patch_type)
|
self.hsr = HSR(game_path=game_path, patch_type=hsr_patch_type)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
from platform import system
|
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.hsr import Game, Patcher
|
||||||
from vollerei.exceptions.patcher import PatcherError, PatchUpdateError
|
from vollerei.exceptions.patcher import PatcherError, PatchUpdateError
|
||||||
from vollerei.hsr.patcher import PatchType
|
from vollerei.hsr.patcher import PatchType
|
||||||
@ -11,8 +11,8 @@ class HSR:
|
|||||||
self, game_path=None, patch_type: PatchType = PatchType.Jadeite
|
self, game_path=None, patch_type: PatchType = PatchType.Jadeite
|
||||||
) -> None:
|
) -> None:
|
||||||
self._game = Game(game_path)
|
self._game = Game(game_path)
|
||||||
print("Game directory:", self._game.path)
|
msg("Game directory:", self._game.path)
|
||||||
print("Game version:", self._game.get_version_str())
|
msg("Game version:", self._game.get_version_str())
|
||||||
self._patcher = Patcher()
|
self._patcher = Patcher()
|
||||||
self._patcher.patch_type = patch_type
|
self._patcher.patch_type = patch_type
|
||||||
|
|
||||||
@ -115,3 +115,6 @@ class HSR:
|
|||||||
self.__patch_jadeite()
|
self.__patch_jadeite()
|
||||||
case PatchType.Astra:
|
case PatchType.Astra:
|
||||||
self.__patch_astra()
|
self.__patch_astra()
|
||||||
|
|
||||||
|
def get_version(self):
|
||||||
|
print(self._game.get_version_str())
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
no_confirm = False
|
no_confirm = False
|
||||||
|
silent_message = False
|
||||||
|
|
||||||
|
|
||||||
def ask(question: str):
|
def ask(question: str):
|
||||||
@ -12,3 +13,12 @@ def ask(question: str):
|
|||||||
# Pacman way, treat all other answers as no
|
# Pacman way, treat all other answers as no
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def msg(*args, **kwargs):
|
||||||
|
"""
|
||||||
|
Print but silentable
|
||||||
|
"""
|
||||||
|
if silent_message:
|
||||||
|
return
|
||||||
|
print(*args, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user