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.2.tar.gz
(7.7 kB
view details)
Built Distribution
File details
Details for the file asyncclick_repl-0.1.2.tar.gz
.
File metadata
- Download URL: asyncclick_repl-0.1.2.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8b724c01864b58c4415e78a83b162d253a335be9865ff1d8536ede8e3fd9d5a |
|
MD5 | c11c6770ed186b2ec2b7f694d2f3d683 |
|
BLAKE2b-256 | d9ca8897f9a25657e2491c59582e67956a650a0dc646f350431fc3e8617d835a |
File details
Details for the file asyncclick_repl-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: asyncclick_repl-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aed90ca75b67eeee8933dbd2c095881ed7d0c5c2fdacbed23d8649d417153e9 |
|
MD5 | 69ed7b771e1333775369726b2cb24ee3 |
|
BLAKE2b-256 | 4d32ddb7ed3613b870ab48811271771458c616f6585cb3d1b54d1c2b0ac8ca54 |