"""LICENSE
Copyright 2015 Hermann Krumrey <hermann@krumreyh.com>

This file is part of toktokkie.

toktokkie is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

toktokkie is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with toktokkie.  If not, see <http://www.gnu.org/licenses/>.
LICENSE"""

import argparse
from puffotter.init import cli_start, argparse_add_verbosity
from toktokkie import sentry_dsn
from toktokkie.scripts import toktokkie_commands


def main(args: argparse.Namespace):
    """
    The main function of this script
    :param args: The command line arguments
    :return: None
    """
    for command_cls in toktokkie_commands:
        if command_cls.name() == args.command:
            command = command_cls(args)
            command.execute()


def define_parser() -> argparse.ArgumentParser:
    """
    :return: The command line parser for this script
    """
    parser = argparse.ArgumentParser()
    argparse_add_verbosity(parser)
    command_parser = parser.add_subparsers(required=True, dest="command")

    for command_cls in toktokkie_commands:
        subparser = command_parser.add_parser(command_cls.name())
        argparse_add_verbosity(subparser)
        command_cls.prepare_parser(subparser)

    return parser


if __name__ == "__main__":

    cli_start(
        main,
        define_parser(),
        "Thanks for using toktokkie!",
        "toktokkie",
        sentry_dsn
    )
