click-repl is a Python library that provides a REPL (Read-Eval-Print Loop) plugin for Click-based command-line applications. It allows users to execute multiple commands in a single interactive session, maintaining a shared context. The current version is 0.3.0, released in June 2023, and it generally follows the release cadence of its upstream dependency, Click.
pip install click-replVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `click-repl` into a basic Click application. It defines a Click group `cli` with two commands, `hello` and `greet`. The `register_repl(cli)` function adds a 'repl' subcommand to the CLI, enabling an interactive session where `hello` and `greet` can be executed. To run, save as `my_app.py` and execute `python my_app.py repl` in your terminal, then type `hello` or `greet yourname`.
Upgrade to Python 3.6+ or pin `click-repl` to a version compatible with Python 2.x (e.g., `click-repl<0.3.0`).
Review custom REPL implementations, especially if directly manipulating `prompt_toolkit` internals, to ensure compatibility with `PromptSession`.
Ensure `click-repl` is version 0.2.0 or higher when using Click 8.x or newer. The current version (0.3.0) is compatible.
Be mindful of state stored in `ctx.obj` within the REPL. Explicitly clear or reset relevant data if a fresh state is required for subsequent commands.
Upgrade `click-repl` to version 0.2.0 or newer using `pip install --upgrade click-repl`. Alternatively, downgrade Click to a version below 8.0.0 using `pip install "click<8.0.0"`.
Ensure that `register_repl()` or `repl()` is called with a `click.Group` instance (e.g., `register_repl(cli)` where `cli` is a `click.Group`) or the context of a group, not a simple `click.Command`.
Upgrade `click-repl` to the latest version to ensure bug fixes related to exception handling are applied. For example: `pip install --upgrade click-repl`.
Install the `click` package using pip: `pip install click`.