Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(description="Throw a dice.")
    parser.add_argument("--faces",
                        "-f",
                        metavar="N",
                        type=int,
                        default=6,
                        help="Number of faces")
    cli = AsynchronousCli({"dice": (dice, parser)}, prog="dice")

    loop = asyncio.get_event_loop()
    loop.run_until_complete(cli.interact())
Exemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser(description='Throw a dice.')
    parser.add_argument('--faces',
                        '-f',
                        metavar='N',
                        type=int,
                        default=6,
                        help='Number of faces')
    cli = AsynchronousCli({'dice': (dice, parser)}, prog='dice')

    loop = asyncio.get_event_loop()
    loop.run_until_complete(cli.interact())
Exemplo n.º 3
0
def make_cli(streams=None):
    parser = argparse.ArgumentParser(description="Display the message history")
    parser.add_argument("--pattern",
                        "-p",
                        type=str,
                        help="pattern to filter hostnames")
    commands = {"history": (get_history, parser)}
    return AsynchronousCli(commands, streams, prog="echo")
Exemplo n.º 4
0
def make_cli(streams=None):
    parser = argparse.ArgumentParser(description="Display the message history")
    parser.add_argument('--pattern',
                        '-p',
                        type=str,
                        help='pattern to filter hostnames')
    commands = {'history': (get_history, parser)}
    return AsynchronousCli(commands, streams, prog='echo')
Exemplo n.º 5
0
def make_cli(streams=None):
    async def say_hello(reader, writer, name=None):
        data = "Hello {}!".format(name) if name else "Hello!"
        writer.write(data.encode() + b"\n")

    parser = argparse.ArgumentParser(description="Say hello")
    parser.add_argument("--name", "-n", type=str)
    commands = {"hello": (say_hello, parser)}
    return AsynchronousCli(commands, streams, prog="hello")
Exemplo n.º 6
0
def make_cli(streams=None):
    @asyncio.coroutine
    def say_hello(reader, writer, name=None):
        data = "Hello {}!".format(name) if name else "Hello!"
        writer.write(data.encode() + b'\n')

    parser = argparse.ArgumentParser(description="Say hello")
    parser.add_argument('--name', '-n', type=str)
    commands = {'hello': (say_hello, parser)}
    return AsynchronousCli(commands, streams, prog='hello')