#!/usr/bin/env python3
# Eryn Wells <eryn@erynwells.me>

'''
A Python interface to my personal website, Erynwells.me.
'''

import argparse
from typing import List
from erynwells_me.scripting import Command
from erynwells_me.weeknotes import WeeknotesCommand


COMMANDS: List[Command] = [
    WeeknotesCommand(),
]


def parse_args(commands: List[Command], argv, *a, **kw):
    parser = argparse.ArgumentParser(*a, **kw)

    subcommands = parser.add_subparsers(title='Subcommands', required=True)
    for command in commands:
        subcommand_parser = subcommands.add_parser(command.name, help=command.help)
        command.add_arguments(subcommand_parser)

    args = parser.parse_args(argv)
    return args


def main(argv):
    args = parse_args(COMMANDS, argv[1:], prog=argv[0])
    return args.handler(args)


if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))
