#!/usr/bin/env python3

import argparse
import logging
import os
from ligbinder.core import LigBinder
from ligbinder.settings import SETTINGS


def get_parser():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-p", "--path",
        help="ligbinder run folder path. default is current working directory",
        default="."
    )
    parser.add_argument(
        "-c", "--config",
        help=f"location of additional configuration file. "
             f"if no config file is provided, all the config values will be the default ones. "
             f"default is config.yml",
        default=None
    )
    parser.add_argument(
        "-v", "--verbosity",
        help="set verbosity level. default is INFO",
        default="INFO",
        choices=["INFO", "WARNING", "ERROR", "CRITICAL"]
    )
    parser.add_argument(
        "-l", "--log",
        help="send the logging output to the specified file",
        default=None
    )
    return parser


parser = get_parser()
args = parser.parse_args()

logging.basicConfig(level=args.verbosity, filename=args.log, filemode='w')

config_file = args.config if args.config is not None else os.path.join(args.path, SETTINGS["config_file"])
config_file = config_file if os.path.exists(config_file) else None

ligbinder = LigBinder(path=args.path, config_file=config_file)
ligbinder.run()
