clickforward


Nameclickforward JSON
Version 0.0.1 PyPI version JSON
download
home_page
SummaryForward all arguments using click without any parsing and without -
upload_time2024-03-05 08:58:22
maintainer
docs_urlNone
authorKamil Cukrowski
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements typing_extensions click
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # clickforward

Forward all click arguments without any parsing and any options from the first
non-option positional argument.

See https://github.com/pallets/click/pull/2686

# Usage

This change introduces a new `clickforward.FORWARD` argument type, which
stops the parser from further parsing arguments. Is it now possible to
forward arguments without any parsing.

Set the `argument` with `nargs=-1` and `type=clickforward.FORWARD` to
perfectly capture all arguments.

Example implementation of docker run` command:

```
import clickforward
import click


@click.group()
@click.option("-v", "--verbose", is_flag=True)
def docker(verbose):
    pass


@docker.command()
@click.option("-v", "--verbose", is_flag=True)
@click.option("-u", "--user")
@click.argument("image")
@click.argument("command", nargs=-1, type=clickforward.FORWARD)
def run(verbose, user, image, command):
    cmdline: List[str] = (
        ["docker"]
        + ["run"]
        + ([f"-u{user}"] if user else [])
        + [image]
        + list(command)
    )
    click.echo(" ".join(shlex.quote(x) for x in cmdline))


docker()
```

Allows for forwarding `sh --help -u -v` to the docker container.

```
$ python ./docker.py -v run -u kamil alpine sh --help -u -v
['docker', 'run', '-ukamil', 'alpine', 'sh', '--help', '-u', '-v']
```

# How it works

The act of importing the module __replaces__ the `click.parser.OptionParser`
parsing function of arguments with custom logic.

I have only tested with click==8.1.7.

# Epilogue

Written by Kamil Cukrowski


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "clickforward",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Kamil Cukrowski",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/3c/ef/4e95e87c9651495ff2f897ec8027c723040f955059e714a63201a3520a1d/clickforward-0.0.1.tar.gz",
    "platform": null,
    "description": "# clickforward\n\nForward all click arguments without any parsing and any options from the first\nnon-option positional argument.\n\nSee https://github.com/pallets/click/pull/2686\n\n# Usage\n\nThis change introduces a new `clickforward.FORWARD` argument type, which\nstops the parser from further parsing arguments. Is it now possible to\nforward arguments without any parsing.\n\nSet the `argument` with `nargs=-1` and `type=clickforward.FORWARD` to\nperfectly capture all arguments.\n\nExample implementation of docker run` command:\n\n```\nimport clickforward\nimport click\n\n\n@click.group()\n@click.option(\"-v\", \"--verbose\", is_flag=True)\ndef docker(verbose):\n    pass\n\n\n@docker.command()\n@click.option(\"-v\", \"--verbose\", is_flag=True)\n@click.option(\"-u\", \"--user\")\n@click.argument(\"image\")\n@click.argument(\"command\", nargs=-1, type=clickforward.FORWARD)\ndef run(verbose, user, image, command):\n    cmdline: List[str] = (\n        [\"docker\"]\n        + [\"run\"]\n        + ([f\"-u{user}\"] if user else [])\n        + [image]\n        + list(command)\n    )\n    click.echo(\" \".join(shlex.quote(x) for x in cmdline))\n\n\ndocker()\n```\n\nAllows for forwarding `sh --help -u -v` to the docker container.\n\n```\n$ python ./docker.py -v run -u kamil alpine sh --help -u -v\n['docker', 'run', '-ukamil', 'alpine', 'sh', '--help', '-u', '-v']\n```\n\n# How it works\n\nThe act of importing the module __replaces__ the `click.parser.OptionParser`\nparsing function of arguments with custom logic.\n\nI have only tested with click==8.1.7.\n\n# Epilogue\n\nWritten by Kamil Cukrowski\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Forward all arguments using click without any parsing and without -",
    "version": "0.0.1",
    "project_urls": {
        "documentation": "https://github.com/Kamilcuk/clickforward",
        "homepage": "https://github.com/Kamilcuk/clickforward",
        "repository": "https://github.com/Kamilcuk/clickforward"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "603e58aaaaf927f68aaeb8f64e88c6ddfeee5880ec7646bcbcdce3b7b4b086c3",
                "md5": "4028bdf80a3aa37308138b5254d02fcd",
                "sha256": "229ca6ab5e11a23205409e9623f029241d287c5351e33aa9e15870f6fcf8dd8f"
            },
            "downloads": -1,
            "filename": "clickforward-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4028bdf80a3aa37308138b5254d02fcd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 3516,
            "upload_time": "2024-03-05T08:58:20",
            "upload_time_iso_8601": "2024-03-05T08:58:20.716259Z",
            "url": "https://files.pythonhosted.org/packages/60/3e/58aaaaf927f68aaeb8f64e88c6ddfeee5880ec7646bcbcdce3b7b4b086c3/clickforward-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3cef4e95e87c9651495ff2f897ec8027c723040f955059e714a63201a3520a1d",
                "md5": "f6ea9fe0c0a62314c46ee08b0a0d9899",
                "sha256": "a9af8aa5863e5a923fc63867358e11b574059b7f970dc09e18e4344122bfed91"
            },
            "downloads": -1,
            "filename": "clickforward-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f6ea9fe0c0a62314c46ee08b0a0d9899",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4002,
            "upload_time": "2024-03-05T08:58:22",
            "upload_time_iso_8601": "2024-03-05T08:58:22.151954Z",
            "url": "https://files.pythonhosted.org/packages/3c/ef/4e95e87c9651495ff2f897ec8027c723040f955059e714a63201a3520a1d/clickforward-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-05 08:58:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Kamilcuk",
    "github_project": "clickforward",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "typing_extensions",
            "specs": []
        },
        {
            "name": "click",
            "specs": []
        }
    ],
    "lcname": "clickforward"
}
        
Elapsed time: 1.22434s