Skip to main content

Command class to add REPL support to existing click groups

Project description

asyncclick-repl

Command to make a REPL out of a group by passing -i or --interactive to the cli. Inspired by click-repl but using native click command and shell completion.

import asyncio

import asyncclick as click

from asyncclick_repl import AsyncREPL


@click.group(cls=AsyncREPL)
async def cli():
    pass


@cli.command()
@click.option("--count", default=1, help="Number of greetings.")
@click.option("--name", prompt="Your name", help="The person to greet.")
async def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for _ in range(count):
        await asyncio.sleep(0.1)
        click.echo(f"Hello, {name}!")


cli(_anyio_backend="asyncio")
myclickapp -i

> hello --count 2 --name Foo
Hello, Foo!
Hello, Foo!
> :q

Features:

  • Tab-completion. Using click's shell completion
  • Execute system commands using ! prefix. Note: ! should be followed by a space e.g ! ls
  • :h show commands help.

Prompt configuration

Use prompt_kwargs to provide configuration to python-prompt-toolkit's Prompt class

import asyncclick as click
from prompt_toolkit.history import FileHistory

from asyncclick_repl import AsyncREPL

prompt_kwargs = {
    "history": FileHistory("./history"),
}


@click.group(cls=AsyncREPL, prompt_kwargs=prompt_kwargs)
async def cli():
    pass


cli()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncclick_repl-0.1.2.tar.gz (7.7 kB view hashes)

Uploaded Source

Built Distribution

asyncclick_repl-0.1.2-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page