#!/usr/bin/python3

import anyio
import asyncclick as click
from microfuse.multiplex import Multiplexer
import logging
import errno
logger = logging.getLogger(__name__)

@click.command()
@click.option("-h","--host", help="Address of the embedded system")
@click.option("-p","--port", type=int, default=8267, help="Port to use")
@click.option("-d","--data", "stream", type=click.Path(), help="Data socket")
@click.option("-r","--repl", type=click.Path(), help="REPL socket")
@click.option("-R","--repl-nr", type=int, default=0, help="Terminal number. Default: zero")
@click.option("-m","--multiplex", is_flag=True, help="Multiplex the REPL?")
@click.option("-M","--mqtt", type=str, help="MQTT broker URL")
@click.option("-t","--retry", type=int, help="number of reconnection attempts")
@click.option("-w","--watchdog", type=float, help="Send keepalive every N seconds")
async def main(**kw):
    if not kw.get("host"):
        raise click.UsageError("Host name is mandatory")
    mplex = Multiplexer(**kw)
    await mplex.run()
    

if __name__ == "__main__":
    main(_anyio_backend="trio")
