import cqh_file
import click

#ctypes.windll.user32.MessageBoxW(0, msg, title, 1)


@click.group()
def cli():
    pass




@click.command()
@click.option("--port", default=8081)
@click.option("--dir")
@click.option("--timeout", default=60)
def serve(port, dir, timeout):
    click.echo("port:{}".format(port))
    click.echo("dir:{}, timeout:{}".format(dir, timeout))
    from cqh_file import __version__
    click.echo("version:{}".format(__version__))
    from cqh_file.serve import create_app

    create_app(port=port, dir=dir, timeout=timeout)

@click.command()
@click.option("--url")
@click.option("--dir")
@click.option("--sleep", default=300)
def client(url, dir, sleep):
    click.echo("url:{}, dir:{}, sleep:{}".format(url,dir, sleep))
    from cqh_file import __version__
    click.echo("version:{}".format(__version__))
    from cqh_file.client import ClientLoop
    loop = ClientLoop(url=url, dir=dir, sleep=sleep)
    loop.loop()

cli.add_command(serve)
cli.add_command(client)


if __name__ == "__main__":
    cli()
