Skip to main content

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

Metadata

Release files for clickforward 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clickforward 0.0.1
File Size Uploaded Provenance
clickforward-0.0.1.tar.gz 4.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for clickforward 0.0.1
File Interpreter ABI Platform
clickforward-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / clickforward-0.0.1.tar.gz

Download URL clickforward-0.0.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a9af8aa5863e5a923fc63867358e11b574059b7f970dc09e18e4344122bfed91
BLAKE2b-256 checksum
How to use checksums
3cef4e95e87c9651495ff2f897ec8027c723040f955059e714a63201a3520a1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8

Release files / clickforward-0.0.1-py3-none-any.whl

Download URL clickforward-0.0.1-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
229ca6ab5e11a23205409e9623f029241d287c5351e33aa9e15870f6fcf8dd8f
BLAKE2b-256 checksum
How to use checksums
603e58aaaaf927f68aaeb8f64e88c6ddfeee5880ec7646bcbcdce3b7b4b086c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8

Security for clickforward 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page