#!/usr/bin/env python

""" MegaQC: a web application that collects results from multiple runs of MultiQC and allows bulk visualisation.
"""

import click
from flask.cli import FlaskGroup

def create_megaqc_app(info):
    import os
    from megaqc.app import create_app
    from megaqc.settings import TestConfig, DevConfig, ProdConfig

    if os.environ.get('MEGAQC_DEBUG', False):
        CONFIG = DevConfig()
    elif os.environ.get('MEGAQC_PRODUCTION', False):
        CONFIG = ProdConfig()
    else:
        CONFIG = TestConfig()
    return create_app(CONFIG)

@click.group(cls=FlaskGroup, create_app=create_megaqc_app)
def cli():
    """Welcome to the MegaQC command line interface!\n
    MegaQC is built using the Flask Python web framework.
    See below for the available commands - for example,
    to start the MegaQC server, use the command: megaqc run"""

if __name__ == '__main__':
    import pkg_resources
    version = pkg_resources.get_distribution("megaqc").version
    print("This is MegaQC v{}\n".format(version))
    cli()
