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.1.tar.gz
(5.4 kB
view details)
Built Distribution
File details
Details for the file asyncclick_repl-0.1.1.tar.gz
.
File metadata
- Download URL: asyncclick_repl-0.1.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.2 Linux/5.15.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29ec7d26d02d7440ee5f1f517e9b09d45cc9bffc780c887044ee6f2cb0353f97 |
|
MD5 | e290c57eb55815b65faa48aedf2eeddd |
|
BLAKE2b-256 | 6faacd25156ca692279ac33c12e2992ab2100ece71fd8929a7b418ded245af06 |
File details
Details for the file asyncclick_repl-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: asyncclick_repl-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.2 Linux/5.15.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1481cdef82960da2808cd1b774fa41beea089c8ae6f080f1ce2f7377fedcc189 |
|
MD5 | c078e35f1f40bf9cf03907495db64787 |
|
BLAKE2b-256 | c4bf377e18b0f7747cd9bbcae0b95ae2f24fcfe40a6503adba7d726a9741d833 |