#!python

import mkinx
import argparse
import warnings

warnings.filterwarnings("ignore", message="numpy.dtype size changed")

# Available commands
COMMANDS = {
    "init": mkinx.init,
    "build": mkinx.build,
    "serve": mkinx.serve,
    "version": mkinx.version,
    "clean": mkinx.clean,
    "autodoc": mkinx.autodoc,
}


parser = argparse.ArgumentParser(description="Building Doc")

parser.add_argument(
    "command", choices=COMMANDS.keys(), nargs="?", help="Available commands for mkinx"
)

parser.add_argument("project_name", nargs="?", help="[init] Your project's name")

parser.add_argument("--version", action="store_true", help="Print mkinx's version")
parser.add_argument(
    "-v",
    "--verbose",
    action="store_true",
    help="[build] verbose flag (Sphinx will stay verbose)",
)
parser.add_argument(
    "-A", "--all", action="store_true", help="[build] Build doc for all projects"
)
parser.add_argument(
    "-F",
    "--force",
    action="store_true",
    help="[build] force the build, no verification asked",
)
parser.add_argument(
    "-o",
    "--only_index",
    action="store_true",
    help="[build] only build projects listed \
in the Documentation's Home",
)
parser.add_argument(
    "-p", "--projects", nargs="*", help="[build] list of projects to build"
)
parser.add_argument(
    "-s",
    "--serve_port",
    nargs="?",
    type=int,
    help="[serve] the server's port, defaults to 8443",
)
parser.add_argument(
    "--offline",
    action="store_true",
    help="[build, serve] Whether references to external APIs \
should be deleted from html files + load material icons locally",
)

args = parser.parse_args()

if args.command:
    try:
        COMMANDS[args.command](args)
    except KeyboardInterrupt:
        print("\n{}Interrupted.{}".format(mkinx.colors.FAIL, mkinx.colors.ENDC))
elif args.version:
    COMMANDS["version"](args)
