59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
import yaml
|
|
|
|
from diceplayer.config.player_config import PlayerConfig
|
|
from diceplayer.logger import logger
|
|
|
|
import argparse
|
|
from importlib import metadata
|
|
|
|
from diceplayer.player import Player
|
|
|
|
VERSION = metadata.version("diceplayer")
|
|
|
|
|
|
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
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(prog="Diceplayer")
|
|
parser.add_argument(
|
|
"-v", "--version", action="version", version="diceplayer-" + VERSION
|
|
)
|
|
parser.add_argument(
|
|
"-c", "--continue", dest="continuation", default=False, action="store_true"
|
|
)
|
|
parser.add_argument(
|
|
"-i",
|
|
"--input",
|
|
dest="infile",
|
|
default="control.yml",
|
|
metavar="INFILE",
|
|
help="input file of diceplayer [default = control.in]",
|
|
)
|
|
parser.add_argument(
|
|
"-o",
|
|
"--output",
|
|
dest="outfile",
|
|
default="run.log",
|
|
metavar="OUTFILE",
|
|
help="output file of diceplayer [default = run.log]",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
logger.set_output_file(args.outfile)
|
|
|
|
config = read_input(args.infile)
|
|
|
|
Player(config).play(continuation=args.continuation)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |