feat: better state_handler
This commit is contained in:
5
diceplayer/cli/__init__.py
Normal file
5
diceplayer/cli/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from .args_model import ArgsModel
|
||||
from .read_input_file import read_input
|
||||
|
||||
|
||||
__all__ = ["ArgsModel", "read_input"]
|
||||
11
diceplayer/cli/args_model.py
Normal file
11
diceplayer/cli/args_model.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class ArgsModel(BaseModel):
|
||||
outfile: str
|
||||
infile: str
|
||||
continuation: bool
|
||||
|
||||
@classmethod
|
||||
def from_args(cls, args):
|
||||
return cls(**vars(args))
|
||||
13
diceplayer/cli/read_input_file.py
Normal file
13
diceplayer/cli/read_input_file.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from diceplayer.config import PlayerConfig
|
||||
from diceplayer.logger import logger
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
def read_input(infile) -> PlayerConfig:
|
||||
try:
|
||||
with open(infile, "r") as f:
|
||||
return PlayerConfig.model_validate(yaml.safe_load(f))
|
||||
except Exception as e:
|
||||
logger.exception("Failed to read input file")
|
||||
raise e
|
||||
Reference in New Issue
Block a user