61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
from diceplayer.cli import ArgsModel, read_input
|
|
from diceplayer.config import PlayerConfig
|
|
from diceplayer.logger import logger
|
|
from diceplayer.player import Player
|
|
|
|
import argparse
|
|
from importlib import metadata
|
|
|
|
|
|
VERSION = metadata.version("diceplayer")
|
|
|
|
|
|
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]",
|
|
)
|
|
parser.add_argument(
|
|
"-f",
|
|
"--force",
|
|
dest="force",
|
|
default=False,
|
|
action="store_true",
|
|
help="force overwrite existing state file if it exists [default = False]",
|
|
)
|
|
args = ArgsModel.from_args(parser.parse_args())
|
|
|
|
logger.set_output_file(args.outfile)
|
|
|
|
config: PlayerConfig
|
|
try:
|
|
config = read_input(args.infile)
|
|
except Exception as e:
|
|
logger.error(f"Failed to read input file: {e}")
|
|
return
|
|
|
|
Player(config).play(continuation=args.continuation, force=args.force)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|