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
Release history Release notifications | RSS feed
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.0.tar.gz
(5.3 kB
view details)
Built Distribution
File details
Details for the file asyncclick-repl-0.1.0.tar.gz
.
File metadata
- Download URL: asyncclick-repl-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.7 CPython/3.8.2 Linux/5.8.0-1036-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1640643a3caea0cb36f52b77ddef34f37b4cb789439e2c991351a6128e6728d |
|
MD5 | d3392df63cb979343560e825c9ae4ac1 |
|
BLAKE2b-256 | 726b420e3e2726d7fa74a5153af7539ba6cc118452291bedf073db56d05d3c04 |
File details
Details for the file asyncclick_repl-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: asyncclick_repl-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.7 CPython/3.8.2 Linux/5.8.0-1036-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b7c7d5858bb06adbd866dda66cc6a0f6f459e7988d1f09a75705c8c66df0152 |
|
MD5 | 01dfbf3a4305b9ca04920441bc8e4cca |
|
BLAKE2b-256 | 90d559c1516033492e9609b68fe5749d3820fdd98bc03fd1945716b67744eaa3 |