REPL plugin for Click
Project description
click-repl
Installation
Installation is done via pip:
pip install click-repl
Usage
In your click app:
import click
from click_repl import register_repl
@click.group()
def cli():
pass
@cli.command()
def hello():
click.echo("Hello world!")
register_repl(cli)
cli()
In the shell:
$ my_app repl
> hello
Hello world!
> ^C
$ echo hello | my_app repl
Hello world!
Features not shown:
- Tab-completion.
- The parent context is reused, which means
ctx.obj
persists between subcommands. If you're keeping caches on that object (like I do), using the app's repl instead of the shell is a huge performance win. !
- prefix executes shell commands.
You can use the internal :help
command to explain usage.
Advanced Usage
For more flexibility over how your REPL works you can use the repl
function
directly instead of register_repl
. For example, in your app:
import click
from click_repl import repl
from prompt_toolkit.history import FileHistory
@click.group()
def cli():
pass
@cli.command()
def myrepl():
prompt_kwargs = {
'history': FileHistory('/etc/myrepl/myrepl-history'),
}
repl(click.get_current_context(), prompt_kwargs=prompt_kwargs)
cli()
And then your custom myrepl
command will be available on your CLI, which
will start a REPL which has its history stored in
/etc/myrepl/myrepl-history
and persist between sessions.
Any arguments that can be passed to the python-prompt-toolkit
Prompt class
can be passed in the prompt_kwargs
argument and will be used when
instantiating your Prompt
.
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
Built Distribution
File details
Details for the file click-repl-0.3.0.tar.gz
.
File metadata
- Download URL: click-repl-0.3.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17849c23dba3d667247dc4defe1757fff98694e90fe37474f3feebb69ced26a9 |
|
MD5 | 6f91210a103e1927be0c3fa26f9c4430 |
|
BLAKE2b-256 | cba257f4ac79838cfae6912f997b4d1a64a858fb0c86d7fcaae6f7b58d267fca |
File details
Details for the file click_repl-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: click_repl-0.3.0-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb7e06deb8da8de86180a33a9da97ac316751c094c6899382da7feeeeb51b812 |
|
MD5 | 0480c45f34b32fd411254e5216fc2656 |
|
BLAKE2b-256 | 52409d857001228658f0d59e97ebd4c346fe73e138c6de1bce61dc568a57c7f8 |