click-repl


Nameclick-repl JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/untitaker/click-repl
SummaryREPL plugin for Click
upload_time2023-06-15 12:43:51
maintainer
docs_urlNone
authorMarkus Unterwaditzer
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            click-repl
===

[![Tests](https://github.com/click-contrib/click-repl/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/click-contrib/click-repl/actions/workflows/tests.yml)
[![License](https://img.shields.io/pypi/l/click-repl?label=License)](https://github.com/click-contrib/click-repl/LICENSE)
![Python - version](https://img.shields.io/badge/python-3%20%7C%203.7%20%7C%203.8%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue)
[![PyPi - version](https://img.shields.io/badge/pypi-v0.2.0-blue)](https://pypi.org/project/click-repl/)
![wheels](https://img.shields.io/piwheels/v/click-repl?label=wheel)
![PyPI - Status](https://img.shields.io/pypi/status/click)
![PyPI - Downloads](https://img.shields.io/pypi/dm/click-repl)

Installation
===

Installation is done via pip:
```
pip install click-repl
```
Usage
===

In your [click](http://click.pocoo.org/) app:

```py
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:

```py
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`](https://github.com/prompt-toolkit/python-prompt-toolkit) [Prompt](http://python-prompt-toolkit.readthedocs.io/en/stable/pages/reference.html?prompt_toolkit.shortcuts.Prompt#prompt_toolkit.shortcuts.Prompt) class
can be passed in the `prompt_kwargs` argument and will be used when
instantiating your `Prompt`.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/untitaker/click-repl",
    "name": "click-repl",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Markus Unterwaditzer",
    "author_email": "markus@unterwaditzer.net",
    "download_url": "https://files.pythonhosted.org/packages/cb/a2/57f4ac79838cfae6912f997b4d1a64a858fb0c86d7fcaae6f7b58d267fca/click-repl-0.3.0.tar.gz",
    "platform": null,
    "description": "click-repl\n===\n\n[![Tests](https://github.com/click-contrib/click-repl/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/click-contrib/click-repl/actions/workflows/tests.yml)\n[![License](https://img.shields.io/pypi/l/click-repl?label=License)](https://github.com/click-contrib/click-repl/LICENSE)\n![Python - version](https://img.shields.io/badge/python-3%20%7C%203.7%20%7C%203.8%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue)\n[![PyPi - version](https://img.shields.io/badge/pypi-v0.2.0-blue)](https://pypi.org/project/click-repl/)\n![wheels](https://img.shields.io/piwheels/v/click-repl?label=wheel)\n![PyPI - Status](https://img.shields.io/pypi/status/click)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/click-repl)\n\nInstallation\n===\n\nInstallation is done via pip:\n```\npip install click-repl\n```\nUsage\n===\n\nIn your [click](http://click.pocoo.org/) app:\n\n```py\nimport click\nfrom click_repl import register_repl\n\n@click.group()\ndef cli():\n    pass\n\n@cli.command()\ndef hello():\n    click.echo(\"Hello world!\")\n\nregister_repl(cli)\ncli()\n```\nIn the shell:\n```\n$ my_app repl\n> hello\nHello world!\n> ^C\n$ echo hello | my_app repl\nHello world!\n```\n**Features not shown:**\n\n- Tab-completion.\n- The parent context is reused, which means `ctx.obj` persists between\n  subcommands. If you're keeping caches on that object (like I do), using the\n  app's repl instead of the shell is a huge performance win.\n- `!` - prefix executes shell commands.\n\nYou can use the internal `:help` command to explain usage.\n\nAdvanced Usage\n===\n\nFor more flexibility over how your REPL works you can use the `repl` function\ndirectly instead of `register_repl`. For example, in your app:\n\n```py\nimport click\nfrom click_repl import repl\nfrom prompt_toolkit.history import FileHistory\n\n@click.group()\ndef cli():\n    pass\n\n@cli.command()\ndef myrepl():\n    prompt_kwargs = {\n        'history': FileHistory('/etc/myrepl/myrepl-history'),\n    }\n    repl(click.get_current_context(), prompt_kwargs=prompt_kwargs)\n    \ncli()\n```\nAnd then your custom `myrepl` command will be available on your CLI, which\nwill start a REPL which has its history stored in\n`/etc/myrepl/myrepl-history` and persist between sessions.\n\nAny arguments that can be passed to the [`python-prompt-toolkit`](https://github.com/prompt-toolkit/python-prompt-toolkit) [Prompt](http://python-prompt-toolkit.readthedocs.io/en/stable/pages/reference.html?prompt_toolkit.shortcuts.Prompt#prompt_toolkit.shortcuts.Prompt) class\ncan be passed in the `prompt_kwargs` argument and will be used when\ninstantiating your `Prompt`.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "REPL plugin for Click",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://github.com/untitaker/click-repl"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "52409d857001228658f0d59e97ebd4c346fe73e138c6de1bce61dc568a57c7f8",
                "md5": "0480c45f34b32fd411254e5216fc2656",
                "sha256": "fb7e06deb8da8de86180a33a9da97ac316751c094c6899382da7feeeeb51b812"
            },
            "downloads": -1,
            "filename": "click_repl-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0480c45f34b32fd411254e5216fc2656",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 10289,
            "upload_time": "2023-06-15T12:43:48",
            "upload_time_iso_8601": "2023-06-15T12:43:48.626818Z",
            "url": "https://files.pythonhosted.org/packages/52/40/9d857001228658f0d59e97ebd4c346fe73e138c6de1bce61dc568a57c7f8/click_repl-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cba257f4ac79838cfae6912f997b4d1a64a858fb0c86d7fcaae6f7b58d267fca",
                "md5": "6f91210a103e1927be0c3fa26f9c4430",
                "sha256": "17849c23dba3d667247dc4defe1757fff98694e90fe37474f3feebb69ced26a9"
            },
            "downloads": -1,
            "filename": "click-repl-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6f91210a103e1927be0c3fa26f9c4430",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 10449,
            "upload_time": "2023-06-15T12:43:51",
            "upload_time_iso_8601": "2023-06-15T12:43:51.141411Z",
            "url": "https://files.pythonhosted.org/packages/cb/a2/57f4ac79838cfae6912f997b4d1a64a858fb0c86d7fcaae6f7b58d267fca/click-repl-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-15 12:43:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "untitaker",
    "github_project": "click-repl",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "click-repl"
}
        
Elapsed time: 0.09109s