This is a Secret Santa game CLI tool.
at main 52 lines 1.3 kB view raw
1"""Main module.""" 2 3import argparse 4import sys 5from pathlib import Path 6 7from .draws import Draw 8from .models import Game 9from .notifications import notify 10 11 12def app() -> None: 13 """Create main app function, entry point for the CLI, using argparse.""" 14 # loads game config 15 parser = argparse.ArgumentParser(description="Secret Santa CLI tool.") 16 parser.add_argument( 17 "config", 18 type=str, 19 help="Path to .yaml file with the configuration of the Secret Santa game.", 20 ) 21 parser.add_argument( 22 "--dry", 23 action="store_true", 24 help="Simulates the game, and doesn't sends the result.", 25 ) 26 parser.add_argument( 27 "--seed", 28 type=str, 29 help="Explicit the seed for the random choices.", 30 default=None, 31 ) 32 args = parser.parse_args() 33 config_file = Path(args.config) 34 if not config_file.is_file(): 35 print("Game config file not found!") 36 sys.exit(1) 37 38 # creates the game 39 game = Game.create(config_file=config_file) 40 # runs the draw 41 draw = Draw( 42 participants=game.participants(), 43 exclusions=game.exclusions, 44 seed=args.seed, 45 ) 46 draw.run() 47 # notify the results 48 notify(game=game, draw=draw, dry=args.dry) 49 50 51if __name__ == "__main__": 52 app()